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

Overview

Strives to provide Rails built-in PostgreSQL adapter (API) compatibility.

Defined Under Namespace

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:     { name: 'timestamp' },
  decimal:      { name: 'decimal' }, # :limit => 1000
  float:        { name: 'float' },
  hstore:       { name: 'hstore' },
  inet:         { name: 'inet' },
  int4range:    { name: 'int4range' },
  int8range:    { name: 'int8range' },
  integer:      { name: 'integer' },
  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' }
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.jdbc_connection_classObject



39
40
41
# File 'lib/arjdbc/postgresql/adapter.rb', line 39

def self.jdbc_connection_class
  ::ActiveRecord::ConnectionAdapters::PostgreSQLJdbcConnection
end

Instance Method Details

#adapter_nameObject



48
49
50
# File 'lib/arjdbc/postgresql/adapter.rb', line 48

def adapter_name
  ADAPTER_NAME
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.



517
518
519
520
521
522
523
524
525
# File 'lib/arjdbc/postgresql/adapter.rb', line 517

def add_order_by_for_association_limiting!(sql, options)
  return sql if options[:order].blank?

  order = options[: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_schemasObject



495
496
497
# File 'lib/arjdbc/postgresql/adapter.rb', line 495

def all_schemas
  select('SELECT nspname FROM pg_namespace').map { |row| row["nspname"] }
end

#build_insert_sql(insert) ⇒ Object

:nodoc:



408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/arjdbc/postgresql/adapter.rb', line 408

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.touch_model_timestamps_unless { |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



491
492
493
# File 'lib/arjdbc/postgresql/adapter.rb', line 491

def build_truncate_statements(table_names)
  ["TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}"]
end

#check_versionObject

:nodoc:



423
424
425
426
427
# File 'lib/arjdbc/postgresql/adapter.rb', line 423

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

#clear_cache!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



467
468
469
470
471
# File 'lib/arjdbc/postgresql/adapter.rb', line 467

def clear_cache!
  super
  # Make sure all query plans are *really* gone
  @connection.execute 'DEALLOCATE ALL' if active?
end

#client_min_messagesObject

Returns the current client message level.



500
501
502
503
504
# File 'lib/arjdbc/postgresql/adapter.rb', line 500

def client_min_messages
  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.



507
508
509
510
# File 'lib/arjdbc/postgresql/adapter.rb', line 507

def client_min_messages=(level)
  # Not supported on Redshift
  redshift? ? nil : super
end

#configure_connectionObject

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.



69
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
# File 'lib/arjdbc/postgresql/adapter.rb', line 69

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.client_min_messages = 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
end

#create_enum(name, values) ⇒ Object

Given a name and an array of values, creates an enum type.



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/arjdbc/postgresql/adapter.rb', line 339

def create_enum(name, values)
  sql_values = values.map { |s| "'#{s}'" }.join(", ")
  query = <<~SQL
      DO $$
      BEGIN
          IF NOT EXISTS (
            SELECT 1 FROM pg_type t
            WHERE t.typname = '#{name}'
          ) THEN
              CREATE TYPE \"#{name}\" AS ENUM (#{sql_values});
          END IF;
      END
      $$;
  SQL
  exec_query(query)
end

#default_index_type?(index) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


404
405
406
# File 'lib/arjdbc/postgresql/adapter.rb', line 404

def default_index_type?(index) # :nodoc:
  index.using == :btree || super
end

#default_sequence_name(table_name, pk = "id") ⇒ Object

:nodoc:



481
482
483
484
485
# File 'lib/arjdbc/postgresql/adapter.rb', line 481

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) ⇒ Object



306
307
308
309
310
# File 'lib/arjdbc/postgresql/adapter.rb', line 306

def disable_extension(name)
  exec_query("DROP EXTENSION IF EXISTS \"#{name}\" CASCADE").tap {
    reload_type_map
  }
end

#enable_extension(name) ⇒ Object



300
301
302
303
304
# File 'lib/arjdbc/postgresql/adapter.rb', line 300

def enable_extension(name)
  exec_query("CREATE EXTENSION IF NOT EXISTS \"#{name}\"").tap {
    reload_type_map
  }
end

#enum_typesObject

Returns a list of defined enum types, and their values.



325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/arjdbc/postgresql/adapter.rb', line 325

def enum_types
  query = <<~SQL
      SELECT
        type.typname AS name,
        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)
      GROUP BY type.typname;
  SQL
  exec_query(query, "SCHEMA").cast_values
end

#escape_bytea(string) ⇒ Object

Note:

quote_string implemented as native



529
530
531
532
# File 'lib/arjdbc/postgresql/adapter.rb', line 529

def escape_bytea(string)
  return unless string
  "\\x#{string.unpack("H*")[0]}"
end

#exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil) ⇒ Object



430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/arjdbc/postgresql/adapter.rb', line 430

def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil)
  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



444
445
446
# File 'lib/arjdbc/postgresql/adapter.rb', line 444

def execute_batch(statements, name = nil)
  execute(combine_multi_statements(statements), name)
end

#explain(arel, binds = []) ⇒ Object



448
449
450
451
# File 'lib/arjdbc/postgresql/adapter.rb', line 448

def explain(arel, binds = [])
  sql, binds = to_sql_and_binds(arel, binds)
  ActiveRecord::ConnectionAdapters::PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query("EXPLAIN #{sql}", 'EXPLAIN', binds))
end

#extension_available?(name) ⇒ Boolean

Returns:

  • (Boolean)


312
313
314
# File 'lib/arjdbc/postgresql/adapter.rb', line 312

def extension_available?(name)
  query_value("SELECT true FROM pg_available_extensions WHERE name = #{quote(name)}", "SCHEMA")
end

#extension_enabled?(name) ⇒ Boolean

Returns:

  • (Boolean)


316
317
318
# File 'lib/arjdbc/postgresql/adapter.rb', line 316

def extension_enabled?(name)
  query_value("SELECT installed_version IS NOT NULL FROM pg_available_extensions WHERE name = #{quote(name)}", "SCHEMA")
end

#extensionsObject



320
321
322
# File 'lib/arjdbc/postgresql/adapter.rb', line 320

def extensions
  exec_query("SELECT extname FROM pg_extension", "SCHEMA").cast_values
end

#get_advisory_lock(lock_id) ⇒ Object

:nodoc:



286
287
288
289
290
291
# File 'lib/arjdbc/postgresql/adapter.rb', line 286

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_versionObject

:nodoc:



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/arjdbc/postgresql/adapter.rb', line 371

def get_database_version # :nodoc:
  begin
    version = @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_algorithmsObject



235
236
237
# File 'lib/arjdbc/postgresql/adapter.rb', line 235

def index_algorithms
  { concurrently: 'CONCURRENTLY' }
end

#jdbc_column_classObject



44
# File 'lib/arjdbc/postgresql/adapter.rb', line 44

def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn end

#last_insert_id_result(sequence_name) ⇒ Object



487
488
489
# File 'lib/arjdbc/postgresql/adapter.rb', line 487

def last_insert_id_result(sequence_name)
  exec_query("SELECT currval('#{sequence_name}')", 'SQL')
end

#max_identifier_lengthObject

Returns the configured supported identifier length supported by PostgreSQL



357
358
359
# File 'lib/arjdbc/postgresql/adapter.rb', line 357

def max_identifier_length
  @max_identifier_length ||= query_value("SHOW max_identifier_length", "SCHEMA").to_i
end

#native_database_typesObject



156
157
158
# File 'lib/arjdbc/postgresql/adapter.rb', line 156

def native_database_types
  NATIVE_DATABASE_TYPES
end

#quote_table_name(name) ⇒ Object



535
536
537
538
539
540
541
542
543
544
# File 'lib/arjdbc/postgresql/adapter.rb', line 535

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:



293
294
295
296
297
298
# File 'lib/arjdbc/postgresql/adapter.rb', line 293

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



550
551
552
553
# File 'lib/arjdbc/postgresql/adapter.rb', line 550

def remove_column(table_name, column_name, type = nil, **options)
  super
  clear_cache!
end

#reset!Object



473
474
475
476
477
478
479
# File 'lib/arjdbc/postgresql/adapter.rb', line 473

def reset!
  clear_cache!
  reset_transaction
  @connection.rollback # Have to deal with rollbacks differently than the AR adapter
  @connection.execute 'DISCARD ALL'
  @connection.configure_connection
end

#session_auth=(user) ⇒ Object

Set the authorized user for this session



362
363
364
365
# File 'lib/arjdbc/postgresql/adapter.rb', line 362

def session_auth=(user)
  clear_cache!
  execute("SET SESSION AUTHORIZATION #{user}")
end

#set_client_encoding(encoding) ⇒ Object



62
63
64
65
# File 'lib/arjdbc/postgresql/adapter.rb', line 62

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_stringsObject



164
165
166
# File 'lib/arjdbc/postgresql/adapter.rb', line 164

def set_standard_conforming_strings
  execute("SET standard_conforming_strings = on", "SCHEMA")
end

#supports_advisory_locks?Boolean

Returns:

  • (Boolean)


243
244
245
# File 'lib/arjdbc/postgresql/adapter.rb', line 243

def supports_advisory_locks?
  true
end

#supports_bulk_alter?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/arjdbc/postgresql/adapter.rb', line 168

def supports_bulk_alter?
  true
end

#supports_check_constraints?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/arjdbc/postgresql/adapter.rb', line 196

def supports_check_constraints?
  true
end

#supports_comments?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/arjdbc/postgresql/adapter.rb', line 216

def supports_comments?
  true
end

#supports_common_table_expressions?Boolean

Returns:

  • (Boolean)


278
279
280
# File 'lib/arjdbc/postgresql/adapter.rb', line 278

def supports_common_table_expressions?
  true
end

#supports_datetime_with_precision?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/arjdbc/postgresql/adapter.rb', line 208

def supports_datetime_with_precision?
  true
end

#supports_ddl_transactions?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/arjdbc/postgresql/adapter.rb', line 239

def supports_ddl_transactions?
  true
end

#supports_explain?Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/arjdbc/postgresql/adapter.rb', line 247

def supports_explain?
  true
end

#supports_expression_index?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/arjdbc/postgresql/adapter.rb', line 184

def supports_expression_index?
  true
end

#supports_extensions?Boolean

Returns:

  • (Boolean)


251
252
253
# File 'lib/arjdbc/postgresql/adapter.rb', line 251

def supports_extensions?
  database_version >= 90200
end

#supports_foreign_keys?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/arjdbc/postgresql/adapter.rb', line 192

def supports_foreign_keys?
  true
end

#supports_foreign_tables?Boolean

Returns:

  • (Boolean)


263
264
265
# File 'lib/arjdbc/postgresql/adapter.rb', line 263

def supports_foreign_tables?
  database_version >= 90300
end

#supports_index_sort_order?Boolean

Returns:

  • (Boolean)


172
173
174
# File 'lib/arjdbc/postgresql/adapter.rb', line 172

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?

Returns:

  • (Boolean)


228
229
230
# File 'lib/arjdbc/postgresql/adapter.rb', line 228

def supports_insert_on_conflict?
  database_version >= 90500
end

#supports_insert_returning?Boolean

Returns:

  • (Boolean)


224
225
226
# File 'lib/arjdbc/postgresql/adapter.rb', line 224

def supports_insert_returning?
  true
end

#supports_json?Boolean

Returns:

  • (Boolean)


212
213
214
# File 'lib/arjdbc/postgresql/adapter.rb', line 212

def supports_json?
  database_version >= 90200
end

#supports_lazy_transactions?Boolean

Returns:

  • (Boolean)


282
283
284
# File 'lib/arjdbc/postgresql/adapter.rb', line 282

def supports_lazy_transactions?
  true
end

#supports_materialized_views?Boolean

Returns:

  • (Boolean)


259
260
261
# File 'lib/arjdbc/postgresql/adapter.rb', line 259

def supports_materialized_views?
  database_version >= 90300
end

#supports_optimizer_hints?Boolean

Returns:

  • (Boolean)


271
272
273
274
275
276
# File 'lib/arjdbc/postgresql/adapter.rb', line 271

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

Returns:

  • (Boolean)


180
181
182
# File 'lib/arjdbc/postgresql/adapter.rb', line 180

def supports_partial_index?
  true
end

#supports_partitioned_indexes?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/arjdbc/postgresql/adapter.rb', line 176

def supports_partitioned_indexes?
  database_version >= 110_000
end

#supports_pgcrypto_uuid?Boolean

Returns:

  • (Boolean)


267
268
269
# File 'lib/arjdbc/postgresql/adapter.rb', line 267

def supports_pgcrypto_uuid?
  database_version >= 90400
end

#supports_ranges?Boolean

Returns:

  • (Boolean)


255
256
257
# File 'lib/arjdbc/postgresql/adapter.rb', line 255

def supports_ranges?
  database_version >= 90200
end

#supports_savepoints?Boolean

Returns:

  • (Boolean)


220
221
222
# File 'lib/arjdbc/postgresql/adapter.rb', line 220

def supports_savepoints?
  true
end

#supports_transaction_isolation?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/arjdbc/postgresql/adapter.rb', line 188

def supports_transaction_isolation?
  true
end

#supports_validate_constraints?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/arjdbc/postgresql/adapter.rb', line 200

def supports_validate_constraints?
  true
end

#supports_views?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/arjdbc/postgresql/adapter.rb', line 204

def supports_views?
  true
end

#use_insert_returning?Boolean

Returns:

  • (Boolean)


367
368
369
# File 'lib/arjdbc/postgresql/adapter.rb', line 367

def use_insert_returning?
  @use_insert_returning
end

#valid_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/arjdbc/postgresql/adapter.rb', line 160

def valid_type?(type)
  !native_database_types[type].nil?
end

#write_query?(sql) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


459
460
461
# File 'lib/arjdbc/postgresql/adapter.rb', line 459

def write_query?(sql) # :nodoc:
  !READ_QUERY.match?(sql)
end