Module: ActiveRecord::ConnectionAdapters::PostgreSQL::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/active_record/connection_adapters/postgresql/utils.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#extract_schema_qualified_name(string) ⇒ Object

Returns an instance of ActiveRecord::ConnectionAdapters::PostgreSQL::Name extracted from string. schema is nil if not specified in string. schema and identifier exclude surrounding quotes (regardless of whether provided in string) string supports the range of schema/table references understood by PostgreSQL, for example:

  • table_name

  • "table.name"

  • schema_name.table_name

  • schema_name."table.name"

  • "schema_name".table_name

  • "schema.name"."table name"



60
61
62
63
64
65
66
67
# File 'lib/active_record/connection_adapters/postgresql/utils.rb', line 60

def extract_schema_qualified_name(string)
  schema, table = string.scan(/[^".]+|"[^"]*"/)
  if table.nil?
    table = schema
    schema = nil
  end
  PostgreSQL::Name.new(schema, table)
end

#unquote_identifier(identifier) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/active_record/connection_adapters/postgresql/utils.rb', line 69

def unquote_identifier(identifier)
  if identifier && identifier.start_with?('"')
    identifier[1..-2]
  else
    identifier
  end
end