Class: ActiveRecord::ConnectionAdapters::RedshiftAdapter
- Inherits:
-
PostgreSQLAdapter
- Object
- PostgreSQLAdapter
- ActiveRecord::ConnectionAdapters::RedshiftAdapter
- Defined in:
- lib/active_record/connection_adapters/redshift_adapter.rb
Constant Summary collapse
- ADAPTER_NAME =
'Redshift'.freeze
Instance Method Summary collapse
-
#column_definitions(table_name) ⇒ Object
Returns the list of a table’s column names, data types, and default values.
-
#configure_connection ⇒ Object
Configures the encoding, verbosity, schema search path, and time zone of the connection.
- #get_advisory_lock(lock_id) ⇒ Object
- #indexes(table_name, name = nil) ⇒ Object
-
#initialize(connection, logger, connection_parameters, config) ⇒ RedshiftAdapter
constructor
A new instance of RedshiftAdapter.
- #postgresql_version ⇒ Object
-
#primary_keys(table) ⇒ Object
Returns just a table’s primary key.
- #release_advisory_lock(lock_id) ⇒ Object
- #supports_extensions? ⇒ Boolean
- #supports_foreign_keys? ⇒ Boolean
- #supports_index_sort_order? ⇒ Boolean
- #supports_materialized_views? ⇒ Boolean
- #supports_partial_index? ⇒ Boolean
- #supports_ranges? ⇒ Boolean
- #supports_statement_cache? ⇒ Boolean
- #supports_transaction_isolation? ⇒ Boolean
- #supports_views? ⇒ Boolean
- #use_insert_returning? ⇒ Boolean
Constructor Details
#initialize(connection, logger, connection_parameters, config) ⇒ RedshiftAdapter
Returns a new instance of RedshiftAdapter.
30 31 32 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 30 def initialize(connection, logger, connection_parameters, config) super end |
Instance Method Details
#column_definitions(table_name) ⇒ Object
Returns the list of a table’s column names, data types, and default values.
The underlying query is roughly:
SELECT column.name, column.type, default.value
FROM column LEFT JOIN default
ON column.table_id = default.table_id
AND column.num = default.column_num
WHERE column.table_id = get_table_id('table_name')
AND column.num > 0
AND NOT column.is_dropped
ORDER BY column.num
If the table name is not prefixed with a schema, the database will take the first match from the schema search path.
Query implementation notes:
- format_type includes the column size constraint, e.g. varchar(50)
- ::regclass is a function that gives the id for a table name
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 130 def column_definitions(table_name) #:nodoc: exec_query(" SELECT a.attname, format_type(a.atttypid, a.atttypmod),\n pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod\n FROM pg_attribute a LEFT JOIN pg_attrdef d\n ON a.attrelid = d.adrelid AND a.attnum = d.adnum\n WHERE a.attrelid = '\#{quote_table_name(table_name)}'::regclass\n AND a.attnum > 0 AND NOT a.attisdropped\n ORDER BY a.attnum\n end_sql\nend\n", 'SCHEMA').rows |
#configure_connection ⇒ Object
Configures the encoding, verbosity, schema search path, and time zone of the connection. This is called by #connect and should not be called manually.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 36 def configure_connection if @config[:encoding] @connection.set_client_encoding(@config[:encoding]) end # self.client_min_messages = @config[:min_messages] || 'warning' self.schema_search_path = @config[:schema_search_path] || @config[:schema_order] # Use standard-conforming strings so we don't have to do the E'...' dance. # set_standard_conforming_strings # If using Active Record's time zone support configure the connection to return # TIMESTAMP WITH ZONE types in UTC. # (SET TIME ZONE does not use an equals sign like other SET variables) # if ActiveRecord::Base.default_timezone == :utc # execute("SET time zone 'UTC'", 'SCHEMA') # elsif @local_tz # execute("SET time zone '#{@local_tz}'", 'SCHEMA') # end # SET statements from :variables config hash # http://www.postgresql.org/docs/8.3/static/sql-set.html variables = @config[:variables] || {} variables.map do |k, v| if v == ':default' || v == :default # Sets the value to the global or compile default execute("SET SESSION #{k} TO DEFAULT", 'SCHEMA') elsif !v.nil? execute("SET SESSION #{k} TO #{quote(v)}", 'SCHEMA') end end end |
#get_advisory_lock(lock_id) ⇒ Object
160 161 162 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 160 def get_advisory_lock(lock_id) lock_id end |
#indexes(table_name, name = nil) ⇒ Object
156 157 158 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 156 def indexes(table_name, name = nil) [] end |
#postgresql_version ⇒ Object
68 69 70 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 68 def postgresql_version return 100000 + 80002 end |
#primary_keys(table) ⇒ Object
Returns just a table’s primary key
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 143 def primary_keys(table) row = exec_query(" SELECT DISTINCT(attr.attname)\n FROM pg_attribute attr\n INNER JOIN pg_depend dep ON attr.attrelid = dep.refobjid AND attr.attnum = dep.refobjsubid\n INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1]\n WHERE cons.contype = 'p'\n AND dep.refobjid = '\#{quote_table_name(table)}'::regclass\n end_sql\n row && row.first\n end\nend\n", 'SCHEMA').rows.map do |row| |
#release_advisory_lock(lock_id) ⇒ Object
164 165 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 164 def release_advisory_lock(lock_id) end |
#supports_extensions? ⇒ Boolean
96 97 98 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 96 def supports_extensions? false end |
#supports_foreign_keys? ⇒ Boolean
88 89 90 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 88 def supports_foreign_keys? false end |
#supports_index_sort_order? ⇒ Boolean
76 77 78 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 76 def supports_index_sort_order? false end |
#supports_materialized_views? ⇒ Boolean
104 105 106 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 104 def supports_materialized_views? false end |
#supports_partial_index? ⇒ Boolean
80 81 82 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 80 def supports_partial_index? false end |
#supports_ranges? ⇒ Boolean
100 101 102 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 100 def supports_ranges? false end |
#supports_statement_cache? ⇒ Boolean
72 73 74 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 72 def supports_statement_cache? false end |
#supports_transaction_isolation? ⇒ Boolean
84 85 86 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 84 def supports_transaction_isolation? false end |
#supports_views? ⇒ Boolean
92 93 94 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 92 def supports_views? false end |
#use_insert_returning? ⇒ Boolean
108 109 110 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 108 def use_insert_returning? false end |