Module: ArJdbc::PostgreSQL
- Included in:
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/arjdbc/postgresql/adapter.rb,
lib/arjdbc/postgresql/column.rb,
lib/arjdbc/postgresql/oid_types.rb,
lib/arjdbc/postgresql/schema_statements.rb,
lib/arjdbc/postgresql/database_statements.rb
Overview
Strives to provide Rails built-in PostgreSQL adapter (API) compatibility.
Defined Under Namespace
Modules: DatabaseStatements, SchemaStatements Classes: ArjdbcTypeMapInitializer
Constant Summary collapse
- ADAPTER_NAME =
'PostgreSQL'
- NATIVE_DATABASE_TYPES =
{ primary_key: 'bigserial primary key', bigint: { name: 'bigint' }, binary: { name: 'bytea' }, bit: { name: 'bit' }, bit_varying: { name: 'bit varying' }, boolean: { name: 'boolean' }, box: { name: 'box' }, char: { name: 'char' }, cidr: { name: 'cidr' }, circle: { name: 'circle' }, citext: { name: 'citext' }, date: { name: 'date' }, daterange: { name: 'daterange' }, datetime: {}, # set dynamically based on datetime_type timestamptz: { name: 'timestamptz' }, decimal: { name: 'decimal' }, # :limit => 1000 float: { name: 'float' }, hstore: { name: 'hstore' }, inet: { name: 'inet' }, int4range: { name: 'int4range' }, int8range: { name: 'int8range' }, integer: { name: 'integer', limit: 4 }, interval: { name: 'interval' }, json: { name: 'json' }, jsonb: { name: 'jsonb' }, line: { name: 'line' }, lseg: { name: 'lseg' }, ltree: { name: 'ltree' }, macaddr: { name: 'macaddr' }, money: { name: 'money' }, numeric: { name: 'numeric' }, numrange: { name: 'numrange' }, oid: { name: 'oid' }, path: { name: 'path' }, point: { name: 'point' }, polygon: { name: 'polygon' }, string: { name: 'character varying' }, text: { name: 'text' }, time: { name: 'time' }, timestamp: { name: 'timestamp' }, tsrange: { name: 'tsrange' }, tstzrange: { name: 'tstzrange' }, tsvector: { name: 'tsvector' }, uuid: { name: 'uuid' }, xml: { name: 'xml' }, enum: {} # special type https://www.postgresql.org/docs/current/datatype-enum.html }
Instance Method Summary collapse
- #adapter_name ⇒ Object
-
#add_enum_value(type_name, value, options = {}) ⇒ Object
Add enum value to an existing enum type.
-
#add_order_by_for_association_limiting!(sql, options) ⇒ Object
ORDER BY clause for the passed order option.
- #all_schemas ⇒ Object
-
#build_insert_sql(insert) ⇒ Object
:nodoc:.
- #build_truncate_statements(table_names) ⇒ Object
-
#check_version ⇒ Object
:nodoc:.
-
#client_min_messages ⇒ Object
Returns the current client message level.
-
#client_min_messages=(level) ⇒ Object
Set the client message level.
-
#configure_connection ⇒ Object
Configures the encoding, verbosity, schema search path, and time zone of the connection.
-
#create_enum(name, values, **options) ⇒ Object
Given a name and an array of values, creates an enum type.
-
#default_index_type?(index) ⇒ Boolean
:nodoc:.
-
#default_sequence_name(table_name, pk = "id") ⇒ Object
:nodoc:.
-
#disable_extension(name, force: false) ⇒ Object
Removes an extension from the database.
-
#disconnect! ⇒ Object
Disconnects from the database if already connected.
-
#drop_enum(name, values = nil, **options) ⇒ Object
Drops an enum type.
- #enable_extension(name) ⇒ Object
-
#enum_types ⇒ Object
Returns a list of defined enum types, and their values.
- #escape_bytea(string) ⇒ Object
-
#exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil, returning: nil) ⇒ Object
:nodoc:.
- #execute_batch(statements, name = nil) ⇒ Object
- #extension_available?(name) ⇒ Boolean
- #extension_enabled?(name) ⇒ Boolean
- #extensions ⇒ Object
-
#get_advisory_lock(lock_id) ⇒ Object
:nodoc:.
-
#get_database_version ⇒ Object
:nodoc:.
- #index_algorithms ⇒ Object
- #jdbc_column_class ⇒ Object
- #last_insert_id_result(sequence_name) ⇒ Object
-
#max_identifier_length ⇒ Object
Returns the configured supported identifier length supported by PostgreSQL.
- #quote_table_name(name) ⇒ Object
-
#release_advisory_lock(lock_id) ⇒ Object
:nodoc:.
-
#remove_column(table_name, column_name, type = nil, **options) ⇒ Object
Need to clear the cache even though the AR adapter doesn't for some reason.
-
#rename_enum(name, options = {}) ⇒ Object
Rename an existing enum type to something else.
-
#rename_enum_value(type_name, options = {}) ⇒ Object
Rename enum value on an existing enum type.
-
#reset! ⇒ Object
We need to make sure to deallocate all the prepared statements since apparently calling close on the statement object doesn't always free the server resources and calling 'DISCARD ALL' fails if we are inside a transaction def clear_cache! super # Make sure all query plans are really gone @connection.execute 'DEALLOCATE ALL' if active? end.
-
#session_auth=(user) ⇒ Object
Set the authorized user for this session.
- #set_client_encoding(encoding) ⇒ Object
- #set_standard_conforming_strings ⇒ Object
- #supports_advisory_locks? ⇒ Boolean
- #supports_bulk_alter? ⇒ Boolean
- #supports_check_constraints? ⇒ Boolean
- #supports_comments? ⇒ Boolean
- #supports_common_table_expressions? ⇒ Boolean
- #supports_datetime_with_precision? ⇒ Boolean
- #supports_ddl_transactions? ⇒ Boolean
- #supports_explain? ⇒ Boolean
- #supports_expression_index? ⇒ Boolean
- #supports_extensions? ⇒ Boolean
- #supports_foreign_keys? ⇒ Boolean
- #supports_foreign_tables? ⇒ Boolean
-
#supports_identity_columns? ⇒ Boolean
:nodoc:.
- #supports_index_sort_order? ⇒ Boolean
- #supports_insert_on_conflict? ⇒ Boolean (also: #supports_insert_on_duplicate_skip?, #supports_insert_on_duplicate_update?, #supports_insert_conflict_target?)
- #supports_insert_returning? ⇒ Boolean
- #supports_json? ⇒ Boolean
- #supports_lazy_transactions? ⇒ Boolean
- #supports_materialized_views? ⇒ Boolean
- #supports_nulls_not_distinct? ⇒ Boolean
- #supports_optimizer_hints? ⇒ Boolean
- #supports_partial_index? ⇒ Boolean
- #supports_partitioned_indexes? ⇒ Boolean
- #supports_pgcrypto_uuid? ⇒ Boolean
- #supports_ranges? ⇒ Boolean
- #supports_savepoints? ⇒ Boolean
- #supports_transaction_isolation? ⇒ Boolean
- #supports_validate_constraints? ⇒ Boolean
- #supports_views? ⇒ Boolean
- #supports_virtual_columns? ⇒ Boolean
- #use_insert_returning? ⇒ Boolean
-
#write_query?(sql) ⇒ Boolean
:nodoc:.
Instance Method Details
#adapter_name ⇒ Object
49 50 51 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 49 def adapter_name ADAPTER_NAME end |
#add_enum_value(type_name, value, options = {}) ⇒ Object
Add enum value to an existing enum type.
410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 410 def add_enum_value(type_name, value, = {}) before, after = .values_at(:before, :after) sql = +"ALTER TYPE #{quote_table_name(type_name)} ADD VALUE '#{value}'" if before && after raise ArgumentError, "Cannot have both :before and :after at the same time" elsif before sql << " BEFORE '#{before}'" elsif after sql << " AFTER '#{after}'" end execute(sql).tap { reload_type_map } end |
#add_order_by_for_association_limiting!(sql, options) ⇒ Object
ORDER BY clause for the passed order option.
PostgreSQL does not allow arbitrary ordering when using DISTINCT ON, so we work around this by wrapping the SQL as a sub-select and ordering in that query.
609 610 611 612 613 614 615 616 617 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 609 def add_order_by_for_association_limiting!(sql, ) return sql if [:order].blank? order = [:order].split(',').collect { |s| s.strip }.reject(&:blank?) order.map! { |s| 'DESC' if s =~ /\bdesc$/i } order = order.zip((0...order.size).to_a).map { |s,i| "id_list.alias_#{i} #{s}" }.join(', ') sql.replace "SELECT * FROM (#{sql}) AS id_list ORDER BY #{order}" end |
#all_schemas ⇒ Object
587 588 589 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 587 def all_schemas select('SELECT nspname FROM pg_namespace').map { |row| row["nspname"] } end |
#build_insert_sql(insert) ⇒ Object
:nodoc:
491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 491 def build_insert_sql(insert) # :nodoc: sql = +"INSERT #{insert.into} #{insert.values_list}" if insert.skip_duplicates? sql << " ON CONFLICT #{insert.conflict_target} DO NOTHING" elsif insert.update_duplicates? sql << " ON CONFLICT #{insert.conflict_target} DO UPDATE SET " sql << insert. { |column| "#{insert.model.quoted_table_name}.#{column} IS NOT DISTINCT FROM excluded.#{column}" } sql << insert.updatable_columns.map { |column| "#{column}=excluded.#{column}" }.join(",") end sql << " RETURNING #{insert.returning}" if insert.returning sql end |
#build_truncate_statements(table_names) ⇒ Object
583 584 585 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 583 def build_truncate_statements(table_names) ["TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}"] end |
#check_version ⇒ Object
:nodoc:
506 507 508 509 510 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 506 def check_version # :nodoc: if database_version < 90300 raise "Your version of PostgreSQL (#{database_version}) is too old. Active Record supports PostgreSQL >= 9.3." end end |
#client_min_messages ⇒ Object
Returns the current client message level.
592 593 594 595 596 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 592 def return nil if redshift? # not supported on Redshift # Need to use #execute so we don't try to access the type map before it is initialized execute('SHOW client_min_messages', 'SCHEMA').values.first.first end |
#client_min_messages=(level) ⇒ Object
Set the client message level.
599 600 601 602 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 599 def (level) # Not supported on Redshift redshift? ? nil : super end |
#configure_connection ⇒ Object
Configures the encoding, verbosity, schema search path, and time zone of the connection.
This is called on connection.connect
and should not be called manually.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 70 def configure_connection #if encoding = config[:encoding] # The client_encoding setting is set by the driver and should not be altered. # If the driver detects a change it will abort the connection. # see http://jdbc.postgresql.org/documentation/91/connect.html # self.set_client_encoding(encoding) #end self. = @config[:min_messages] || 'warning' self.schema_search_path = @config[:schema_search_path] || @config[:schema_order] # Use standard-conforming strings if available 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.default_timezone == :utc execute("SET time zone 'UTC'", 'SCHEMA') elsif tz = local_tz execute("SET time zone '#{tz}'", 'SCHEMA') end unless redshift? # Set interval output format to ISO 8601 for ease of parsing by ActiveSupport::Duration.parse execute("SET intervalstyle = iso_8601", "SCHEMA") # SET statements from :variables config hash # http://www.postgresql.org/docs/8.3/static/sql-set.html (@config[: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 reload_type_map end |
#create_enum(name, values, **options) ⇒ Object
Given a name and an array of values, creates an enum type.
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 364 def create_enum(name, values, **) sql_values = values.map { |s| quote(s) }.join(", ") scope = quoted_scope(name) query = <<~SQL DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_type t JOIN pg_namespace n ON t.typnamespace = n.oid WHERE t.typname = #{scope[:name]} AND n.nspname = #{scope[:schema]} ) THEN CREATE TYPE #{quote_table_name(name)} AS ENUM (#{sql_values}); END IF; END $$; SQL internal_exec_query(query).tap { reload_type_map } end |
#default_index_type?(index) ⇒ Boolean
:nodoc:
487 488 489 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 487 def default_index_type?(index) # :nodoc: index.using == :btree || super end |
#default_sequence_name(table_name, pk = "id") ⇒ Object
:nodoc:
573 574 575 576 577 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 573 def default_sequence_name(table_name, pk = "id") #:nodoc: serial_sequence(table_name, pk) rescue ActiveRecord::StatementInvalid %Q("#{table_name}_#{pk}_seq") end |
#disable_extension(name, force: false) ⇒ Object
Removes an extension from the database.
[:force] Set to +:cascade+ to drop dependent objects as well. Defaults to false.
322 323 324 325 326 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 322 def disable_extension(name, force: false) internal_exec_query("DROP EXTENSION IF EXISTS \"#{name}\"#{' CASCADE' if force == :cascade}").tap { reload_type_map } end |
#disconnect! ⇒ Object
Disconnects from the database if already connected. Otherwise, this method does nothing.
565 566 567 568 569 570 571 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 565 def disconnect! @lock.synchronize do super @raw_connection&.close @raw_connection = nil end end |
#drop_enum(name, values = nil, **options) ⇒ Object
Drops an enum type.
If the if_exists: true option is provided, the enum is dropped only if it exists. Otherwise, if the enum doesn't exist, an error is raised.
The +values+ parameter will be ignored if present. It can be helpful to provide this in a migration's +change+ method so it can be reverted. In that case, +values+ will be used by #create_enum.
395 396 397 398 399 400 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 395 def drop_enum(name, values = nil, **) query = <<~SQL DROP TYPE#{' IF EXISTS' if [:if_exists]} #{quote_table_name(name)}; SQL internal_exec_query(query).tap { reload_type_map } end |
#enable_extension(name) ⇒ Object
309 310 311 312 313 314 315 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 309 def enable_extension(name, **) schema, name = name.to_s.split(".").values_at(-2, -1) sql = +"CREATE EXTENSION IF NOT EXISTS \"#{name}\"" sql << " SCHEMA #{schema}" if schema internal_exec_query(sql).tap { reload_type_map } end |
#enum_types ⇒ Object
Returns a list of defined enum types, and their values.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 341 def enum_types query = <<~SQL SELECT type.typname AS name, type.OID AS oid, n.nspname AS schema, string_agg(enum.enumlabel, ',' ORDER BY enum.enumsortorder) AS value FROM pg_enum AS enum JOIN pg_type AS type ON (type.oid = enum.enumtypid) JOIN pg_namespace n ON type.typnamespace = n.oid WHERE n.nspname = ANY (current_schemas(false)) GROUP BY type.OID, n.nspname, type.typname; SQL internal_exec_query(query, "SCHEMA", allow_retry: true, materialize_transactions: false).cast_values.each_with_object({}) do |row, memo| name, schema = row[0], row[2] schema = nil if schema == current_schema full_name = [schema, name].compact.join(".") memo[full_name] = row.last end.to_a end |
#escape_bytea(string) ⇒ Object
quote_string implemented as native
621 622 623 624 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 621 def escape_bytea(string) return unless string "\\x#{string.unpack("H*")[0]}" end |
#exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil, returning: nil) ⇒ Object
:nodoc:
512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 512 def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil, returning: nil) # :nodoc: val = super if !use_insert_returning? && pk unless sequence_name table_ref = extract_table_ref_from_insert_sql(sql) sequence_name = default_sequence_name(table_ref, pk) return val unless sequence_name end last_insert_id_result(sequence_name) else val end end |
#execute_batch(statements, name = nil) ⇒ Object
526 527 528 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 526 def execute_batch(statements, name = nil) execute(combine_multi_statements(statements), name) end |
#extension_available?(name) ⇒ Boolean
328 329 330 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 328 def extension_available?(name) query_value("SELECT true FROM pg_available_extensions WHERE name = #{quote(name)}", "SCHEMA") end |
#extension_enabled?(name) ⇒ Boolean
332 333 334 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 332 def extension_enabled?(name) query_value("SELECT installed_version IS NOT NULL FROM pg_available_extensions WHERE name = #{quote(name)}", "SCHEMA") end |
#extensions ⇒ Object
336 337 338 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 336 def extensions internal_exec_query("SELECT extname FROM pg_extension", "SCHEMA", allow_retry: true, materialize_transactions: false).cast_values end |
#get_advisory_lock(lock_id) ⇒ Object
:nodoc:
295 296 297 298 299 300 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 295 def get_advisory_lock(lock_id) # :nodoc: unless lock_id.is_a?(Integer) && lock_id.bit_length <= 63 raise(ArgumentError, "PostgreSQL requires advisory lock ids to be a signed 64 bit integer") end query_value("SELECT pg_try_advisory_lock(#{lock_id})") end |
#get_database_version ⇒ Object
:nodoc:
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 454 def get_database_version # :nodoc: begin version = valid_raw_connection.database_product if match = version.match(/([\d\.]*\d).*?/) version = match[1].split('.').map(&:to_i) # PostgreSQL version representation does not have more than 4 digits # From version 10 onwards, PG has changed its versioning policy to # limit it to only 2 digits. i.e. in 10.x, 10 being the major # version and x representing the patch release # Refer to: # https://www.postgresql.org/support/versioning/ # https://www.postgresql.org/docs/10/static/libpq-status.html -> PQserverVersion() # for more info if version.size >= 3 (version[0] * 100 + version[1]) * 100 + version[2] elsif version.size == 2 if version[0] >= 10 version[0] * 100 * 100 + version[1] else (version[0] * 100 + version[1]) * 100 end elsif version.size == 1 version[0] * 100 * 100 else 0 end else 0 end end end |
#index_algorithms ⇒ Object
244 245 246 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 244 def index_algorithms { concurrently: 'CONCURRENTLY' } end |
#jdbc_column_class ⇒ Object
45 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 45 def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn end |
#last_insert_id_result(sequence_name) ⇒ Object
579 580 581 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 579 def last_insert_id_result(sequence_name) exec_query("SELECT currval('#{sequence_name}')", 'SQL') end |
#max_identifier_length ⇒ Object
Returns the configured supported identifier length supported by PostgreSQL
440 441 442 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 440 def max_identifier_length @max_identifier_length ||= query_value("SHOW max_identifier_length", "SCHEMA").to_i end |
#quote_table_name(name) ⇒ Object
627 628 629 630 631 632 633 634 635 636 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 627 def quote_table_name(name) schema, name_part = extract_pg_identifier_from_name(name.to_s) unless name_part quote_column_name(schema) else table_name, name_part = extract_pg_identifier_from_name(name_part) "#{quote_column_name(schema)}.#{quote_column_name(table_name)}" end end |
#release_advisory_lock(lock_id) ⇒ Object
:nodoc:
302 303 304 305 306 307 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 302 def release_advisory_lock(lock_id) # :nodoc: unless lock_id.is_a?(Integer) && lock_id.bit_length <= 63 raise(ArgumentError, "PostgreSQL requires advisory lock ids to be a signed 64 bit integer") end query_value("SELECT pg_advisory_unlock(#{lock_id})") end |
#remove_column(table_name, column_name, type = nil, **options) ⇒ Object
Need to clear the cache even though the AR adapter doesn't for some reason
642 643 644 645 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 642 def remove_column(table_name, column_name, type = nil, **) super clear_cache! end |
#rename_enum(name, options = {}) ⇒ Object
Rename an existing enum type to something else.
403 404 405 406 407 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 403 def rename_enum(name, = {}) to = .fetch(:to) { raise ArgumentError, ":to is required" } exec_query("ALTER TYPE #{quote_table_name(name)} RENAME TO #{to}").tap { reload_type_map } end |
#rename_enum_value(type_name, options = {}) ⇒ Object
Rename enum value on an existing enum type.
426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 426 def rename_enum_value(type_name, = {}) unless database_version >= 10_00_00 # >= 10.0 raise ArgumentError, "Renaming enum values is only supported in PostgreSQL 10 or later" end from = .fetch(:from) { raise ArgumentError, ":from is required" } to = .fetch(:to) { raise ArgumentError, ":to is required" } execute("ALTER TYPE #{quote_table_name(type_name)} RENAME VALUE '#{from}' TO '#{to}'").tap { reload_type_map } end |
#reset! ⇒ Object
We need to make sure to deallocate all the prepared statements since apparently calling close on the statement object doesn't always free the server resources and calling 'DISCARD ALL' fails if we are inside a transaction def clear_cache! super # Make sure all query plans are really gone @connection.execute 'DEALLOCATE ALL' if active? end
550 551 552 553 554 555 556 557 558 559 560 561 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 550 def reset! @lock.synchronize do return connect! unless @raw_connection # Have to deal with rollbacks differently than the AR adapter @raw_connection.rollback @raw_connection.execute("DISCARD ALL") super end end |
#session_auth=(user) ⇒ Object
Set the authorized user for this session
445 446 447 448 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 445 def session_auth=(user) clear_cache! execute("SET SESSION AUTHORIZATION #{user}") end |
#set_client_encoding(encoding) ⇒ Object
63 64 65 66 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 63 def set_client_encoding(encoding) ActiveRecord::Base.logger.warn "client_encoding is set by the driver and should not be altered, ('#{encoding}' ignored)" ActiveRecord::Base.logger.debug "Set the 'allowEncodingChanges' driver property (e.g. using config[:properties]) if you need to override the client encoding when doing a copy." end |
#set_standard_conforming_strings ⇒ Object
161 162 163 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 161 def set_standard_conforming_strings execute("SET standard_conforming_strings = on", "SCHEMA") end |
#supports_advisory_locks? ⇒ Boolean
252 253 254 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 252 def supports_advisory_locks? true end |
#supports_bulk_alter? ⇒ Boolean
165 166 167 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 165 def supports_bulk_alter? true end |
#supports_check_constraints? ⇒ Boolean
193 194 195 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 193 def supports_check_constraints? true end |
#supports_comments? ⇒ Boolean
213 214 215 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 213 def supports_comments? true end |
#supports_common_table_expressions? ⇒ Boolean
287 288 289 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 287 def supports_common_table_expressions? true end |
#supports_datetime_with_precision? ⇒ Boolean
205 206 207 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 205 def supports_datetime_with_precision? true end |
#supports_ddl_transactions? ⇒ Boolean
248 249 250 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 248 def supports_ddl_transactions? true end |
#supports_explain? ⇒ Boolean
256 257 258 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 256 def supports_explain? true end |
#supports_expression_index? ⇒ Boolean
181 182 183 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 181 def supports_expression_index? true end |
#supports_extensions? ⇒ Boolean
260 261 262 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 260 def supports_extensions? database_version >= 90200 end |
#supports_foreign_keys? ⇒ Boolean
189 190 191 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 189 def supports_foreign_keys? true end |
#supports_foreign_tables? ⇒ Boolean
272 273 274 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 272 def supports_foreign_tables? database_version >= 90300 end |
#supports_identity_columns? ⇒ Boolean
:nodoc:
236 237 238 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 236 def supports_identity_columns? # :nodoc: database_version >= 10_00_00 # >= 10.0 end |
#supports_index_sort_order? ⇒ Boolean
169 170 171 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 169 def supports_index_sort_order? true end |
#supports_insert_on_conflict? ⇒ Boolean Also known as: supports_insert_on_duplicate_skip?, supports_insert_on_duplicate_update?, supports_insert_conflict_target?
225 226 227 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 225 def supports_insert_on_conflict? database_version >= 90500 end |
#supports_insert_returning? ⇒ Boolean
221 222 223 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 221 def supports_insert_returning? true end |
#supports_json? ⇒ Boolean
209 210 211 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 209 def supports_json? database_version >= 90200 end |
#supports_lazy_transactions? ⇒ Boolean
291 292 293 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 291 def supports_lazy_transactions? true end |
#supports_materialized_views? ⇒ Boolean
268 269 270 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 268 def supports_materialized_views? database_version >= 90300 end |
#supports_nulls_not_distinct? ⇒ Boolean
240 241 242 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 240 def supports_nulls_not_distinct? database_version >= 15_00_00 # >= 15.0 end |
#supports_optimizer_hints? ⇒ Boolean
280 281 282 283 284 285 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 280 def supports_optimizer_hints? unless defined?(@has_pg_hint_plan) @has_pg_hint_plan = extension_available?("pg_hint_plan") end @has_pg_hint_plan end |
#supports_partial_index? ⇒ Boolean
177 178 179 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 177 def supports_partial_index? true end |
#supports_partitioned_indexes? ⇒ Boolean
173 174 175 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 173 def supports_partitioned_indexes? database_version >= 110_000 end |
#supports_pgcrypto_uuid? ⇒ Boolean
276 277 278 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 276 def supports_pgcrypto_uuid? database_version >= 90400 end |
#supports_ranges? ⇒ Boolean
264 265 266 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 264 def supports_ranges? database_version >= 90200 end |
#supports_savepoints? ⇒ Boolean
217 218 219 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 217 def supports_savepoints? true end |
#supports_transaction_isolation? ⇒ Boolean
185 186 187 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 185 def supports_transaction_isolation? true end |
#supports_validate_constraints? ⇒ Boolean
197 198 199 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 197 def supports_validate_constraints? true end |
#supports_views? ⇒ Boolean
201 202 203 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 201 def supports_views? true end |
#supports_virtual_columns? ⇒ Boolean
232 233 234 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 232 def supports_virtual_columns? database_version >= 12_00_00 # >= 12.0 end |
#use_insert_returning? ⇒ Boolean
450 451 452 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 450 def use_insert_returning? @use_insert_returning end |
#write_query?(sql) ⇒ Boolean
:nodoc:
536 537 538 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 536 def write_query?(sql) # :nodoc: !READ_QUERY.match?(sql) end |