Module: ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting::ClassMethods

Defined in:
lib/active_record/connection_adapters/postgresql/quoting.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#column_name_matcherObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_record/connection_adapters/postgresql/quoting.rb', line 13

def column_name_matcher
  /
    \A
    (
      (?:
        # "schema_name"."table_name"."column_name"::type_name | function(one or no argument)::type_name
        ((?:\w+\.|"\w+"\.){,2}(?:\w+|"\w+")(?:::\w+)? | \w+\((?:|\g<2>)\)(?:::\w+)?)
      )
      (?:(?:\s+AS)?\s+(?:\w+|"\w+"))?
    )
    (?:\s*,\s*\g<1>)*
    \z
  /ix
end

#column_name_with_order_matcherObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_record/connection_adapters/postgresql/quoting.rb', line 28

def column_name_with_order_matcher
  /
    \A
    (
      (?:
        # "schema_name"."table_name"."column_name"::type_name | function(one or no argument)::type_name
        ((?:\w+\.|"\w+"\.){,2}(?:\w+|"\w+")(?:::\w+)? | \w+\((?:|\g<2>)\)(?:::\w+)?)
      )
      (?:\s+COLLATE\s+"\w+")?
      (?:\s+ASC|\s+DESC)?
      (?:\s+NULLS\s+(?:FIRST|LAST))?
    )
    (?:\s*,\s*\g<1>)*
    \z
  /ix
end

#quote_column_name(name) ⇒ Object

Quotes column names for use in SQL queries.



46
47
48
# File 'lib/active_record/connection_adapters/postgresql/quoting.rb', line 46

def quote_column_name(name) # :nodoc:
  QUOTED_COLUMN_NAMES[name] ||= PG::Connection.quote_ident(name.to_s).freeze
end

#quote_table_name(name) ⇒ Object

Checks the following cases:

  • table_name

  • “table.name”

  • schema_name.table_name

  • schema_name.“table.name”

  • “schema.name”.table_name

  • “schema.name”.“table.name”



58
59
60
# File 'lib/active_record/connection_adapters/postgresql/quoting.rb', line 58

def quote_table_name(name) # :nodoc:
  QUOTED_TABLE_NAMES[name] ||= Utils.extract_schema_qualified_name(name.to_s).quoted.freeze
end