Module: ArJdbc::PostgreSQL
- Defined in:
- lib/arjdbc/postgresql/adapter.rb
Defined Under Namespace
Modules: Column
Class Method Summary collapse
Instance Method Summary collapse
-
#adapter_name ⇒ Object
:nodoc:.
-
#add_column(table_name, column_name, type, options = {}) ⇒ Object
Adds a new column to the named table.
-
#add_order_by_for_association_limiting!(sql, options) ⇒ Object
ORDER BY clause for the passed order option.
- #all_schemas ⇒ Object
- #arel2_visitors ⇒ Object
-
#change_column(table_name, column_name, type, options = {}) ⇒ Object
Changes the column of a table.
-
#change_column_default(table_name, column_name, default) ⇒ Object
Changes the default value of a table column.
- #change_column_null(table_name, column_name, null, default = nil) ⇒ Object
- #create_database(name, options = {}) ⇒ Object
- #create_savepoint ⇒ Object
- #create_schema(schema_name, pg_username) ⇒ Object
- #default_sequence_name(table_name, pk = nil) ⇒ Object
-
#disable_referential_integrity(&block) ⇒ Object
:nodoc:.
-
#distinct(columns, order_by) ⇒ Object
SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
- #drop_database(name) ⇒ Object
- #drop_schema(schema_name) ⇒ Object
- #escape_bytea(s) ⇒ Object
-
#indexes(table_name, name = nil) ⇒ Object
From postgresql_adapter.rb.
- #last_insert_id(table, sequence_name) ⇒ Object
- #modify_types(tp) ⇒ Object
- #pg_columns(table_name, name = nil) ⇒ Object
- #pg_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
-
#pk_and_sequence_for(table) ⇒ Object
Find a table’s primary key and sequence.
- #postgresql_version ⇒ Object
- #primary_key(table) ⇒ Object
-
#quote(value, column = nil) ⇒ Object
:nodoc:.
- #quote_column_name(name) ⇒ Object
- #quote_table_name(name) ⇒ Object
-
#quoted_date(value) ⇒ Object
:nodoc:.
- #recreate_database(name) ⇒ Object
- #release_savepoint ⇒ Object
-
#remove_index(table_name, options) ⇒ Object
:nodoc:.
-
#rename_column(table_name, column_name, new_column_name) ⇒ Object
:nodoc:.
- #rename_table(name, new_name) ⇒ Object
-
#reset_pk_sequence!(table, pk = nil, sequence = nil) ⇒ Object
Resets sequence to the max value of the table’s pk if present.
- #rollback_to_savepoint ⇒ Object
- #structure_dump ⇒ Object
-
#supports_count_distinct? ⇒ Boolean
:nodoc:.
- #supports_ddl_transactions? ⇒ Boolean
- #supports_insert_with_returning? ⇒ Boolean
-
#supports_migrations? ⇒ Boolean
Does PostgreSQL support migrations?.
- #supports_savepoints? ⇒ Boolean
-
#supports_standard_conforming_strings? ⇒ Boolean
Does PostgreSQL support standard conforming strings?.
-
#table_alias_length ⇒ Object
Returns the configured supported identifier length supported by PostgreSQL, or report the default of 63 on PostgreSQL 7.x.
- #tables ⇒ Object
-
#type_to_sql(type, limit = nil, precision = nil, scale = nil) ⇒ Object
:nodoc:.
Class Method Details
.column_selector ⇒ Object
14 15 16 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 14 def self.column_selector [/postgre/i, lambda {|cfg,col| col.extend(::ArJdbc::PostgreSQL::Column)}] end |
.extended(mod) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 7 def self.extended(mod) (class << mod; self; end).class_eval do alias_chained_method :insert, :query_dirty, :pg_insert alias_chained_method :columns, :query_cache, :pg_columns end end |
.jdbc_connection_class ⇒ Object
18 19 20 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 18 def self.jdbc_connection_class ::ActiveRecord::ConnectionAdapters::PostgresJdbcConnection end |
Instance Method Details
#adapter_name ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 100 def adapter_name #:nodoc: 'PostgreSQL' end |
#add_column(table_name, column_name, type, options = {}) ⇒ Object
Adds a new column to the named table. See TableDefinition#column for details of the options you can use.
502 503 504 505 506 507 508 509 510 511 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 502 def add_column(table_name, column_name, type, = {}) default = [:default] notnull = [:null] == false # Add the column. execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, [:limit], [:precision], [:scale])}") change_column_default(table_name, column_name, default) if () change_column_null(table_name, column_name, false, default) if notnull 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.
426 427 428 429 430 431 432 433 434 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 426 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
364 365 366 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 364 def all_schemas select('select nspname from pg_namespace').map {|r| r["nspname"] } end |
#arel2_visitors ⇒ Object
104 105 106 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 104 def arel2_visitors {'jdbcpostgresql' => ::Arel::Visitors::PostgreSQL} end |
#change_column(table_name, column_name, type, options = {}) ⇒ Object
Changes the column of a table.
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 514 def change_column(table_name, column_name, type, = {}) quoted_table_name = quote_table_name(table_name) begin execute "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{type_to_sql(type, [:limit], [:precision], [:scale])}" rescue ActiveRecord::StatementInvalid => e raise e if postgresql_version > 80000 # This is PostgreSQL 7.x, so we have to use a more arcane way of doing it. begin begin_db_transaction tmp_column_name = "#{column_name}_ar_tmp" add_column(table_name, tmp_column_name, type, ) execute "UPDATE #{quoted_table_name} SET #{quote_column_name(tmp_column_name)} = CAST(#{quote_column_name(column_name)} AS #{type_to_sql(type, [:limit], [:precision], [:scale])})" remove_column(table_name, column_name) rename_column(table_name, tmp_column_name, column_name) commit_db_transaction rescue rollback_db_transaction end end change_column_default(table_name, column_name, [:default]) if () change_column_null(table_name, column_name, [:null], [:default]) if .key?(:null) end |
#change_column_default(table_name, column_name, default) ⇒ Object
Changes the default value of a table column.
540 541 542 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 540 def change_column_default(table_name, column_name, default) execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{quote(default)}" end |
#change_column_null(table_name, column_name, null, default = nil) ⇒ Object
544 545 546 547 548 549 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 544 def change_column_null(table_name, column_name, null, default = nil) unless null || default.nil? execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL") end execute("ALTER TABLE #{quote_table_name(table_name)} ALTER #{quote_column_name(column_name)} #{null ? 'DROP' : 'SET'} NOT NULL") end |
#create_database(name, options = {}) ⇒ Object
348 349 350 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 348 def create_database(name, = {}) execute "CREATE DATABASE \"#{name}\" ENCODING='#{[:encoding] || 'utf8'}'" end |
#create_savepoint ⇒ Object
157 158 159 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 157 def create_savepoint execute("SAVEPOINT #{current_savepoint_name}") end |
#create_schema(schema_name, pg_username) ⇒ Object
356 357 358 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 356 def create_schema(schema_name, pg_username) execute("CREATE SCHEMA \"#{schema_name}\" AUTHORIZATION \"#{pg_username}\"") end |
#default_sequence_name(table_name, pk = nil) ⇒ Object
175 176 177 178 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 175 def default_sequence_name(table_name, pk = nil) default_pk, default_seq = pk_and_sequence_for(table_name) default_seq || "#{table_name}_#{pk || default_pk || 'id'}_seq" end |
#disable_referential_integrity(&block) ⇒ Object
:nodoc:
489 490 491 492 493 494 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 489 def disable_referential_integrity(&block) #:nodoc: execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";")) yield ensure execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";")) end |
#distinct(columns, order_by) ⇒ Object
SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
PostgreSQL requires the ORDER BY columns in the select list for distinct queries, and requires that the ORDER BY include the distinct column.
distinct("posts.id", "posts.created_at desc")
407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 407 def distinct(columns, order_by) return "DISTINCT #{columns}" if order_by.blank? # construct a clean list of column names from the ORDER BY clause, removing # any asc/desc modifiers order_columns = order_by.split(',').collect { |s| s.split.first } order_columns.delete_if(&:blank?) order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" } # return a DISTINCT ON() clause that's distinct on the columns we want but includes # all the required columns for the ORDER BY to work properly sql = "DISTINCT ON (#{columns}) #{columns}, " sql << order_columns * ', ' end |
#drop_database(name) ⇒ Object
352 353 354 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 352 def drop_database(name) execute "DROP DATABASE IF EXISTS \"#{name}\"" end |
#drop_schema(schema_name) ⇒ Object
360 361 362 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 360 def drop_schema(schema_name) execute("DROP SCHEMA \"#{schema_name}\"") end |
#escape_bytea(s) ⇒ Object
458 459 460 461 462 463 464 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 458 def escape_bytea(s) if s result = '' s.each_byte { |c| result << sprintf('\\\\%03o', c) } result end end |
#indexes(table_name, name = nil) ⇒ Object
From postgresql_adapter.rb
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 306 def indexes(table_name, name = nil) result = select_rows(<<-SQL, name) SELECT i.relname, d.indisunique, a.attname FROM pg_class t, pg_class i, pg_index d, pg_attribute a WHERE i.relkind = 'i' AND d.indexrelid = i.oid AND d.indisprimary = 'f' AND t.oid = d.indrelid AND t.relname = '#{table_name}' AND a.attrelid = t.oid AND ( d.indkey[0]=a.attnum OR d.indkey[1]=a.attnum OR d.indkey[2]=a.attnum OR d.indkey[3]=a.attnum OR d.indkey[4]=a.attnum OR d.indkey[5]=a.attnum OR d.indkey[6]=a.attnum OR d.indkey[7]=a.attnum OR d.indkey[8]=a.attnum OR d.indkey[9]=a.attnum ) ORDER BY i.relname SQL current_index = nil indexes = [] result.each do |row| if current_index != row[0] indexes << ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, row[0], row[1] == "t", []) current_index = row[0] end indexes.last.columns << row[2] end indexes end |
#last_insert_id(table, sequence_name) ⇒ Object
339 340 341 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 339 def last_insert_id(table, sequence_name) Integer(select_value("SELECT currval('#{sequence_name}')")) end |
#modify_types(tp) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 85 def modify_types(tp) tp[:primary_key] = "serial primary key" tp[:string][:limit] = 255 tp[:integer][:limit] = nil tp[:boolean] = { :name => "boolean" } tp[:float] = { :name => "float" } tp[:text] = { :name => "text" } tp[:datetime] = { :name => "timestamp" } tp[:timestamp] = { :name => "timestamp" } tp[:time] = { :name => "time" } tp[:date] = { :name => "date" } tp[:decimal] = { :name => "decimal" } tp end |
#pg_columns(table_name, name = nil) ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 282 def pg_columns(table_name, name=nil) schema_name = @config[:schema_search_path] if table_name =~ /\./ parts = table_name.split(/\./) table_name = parts.pop schema_name = parts.join(".") end schema_list = if schema_name.nil? [] else schema_name.split(/\s*,\s*/) end while schema_list.size > 1 s = schema_list.shift begin return @connection.columns_internal(table_name, name, s) rescue ActiveRecord::JDBCError=>ignored_for_next_schema end end s = schema_list.shift return @connection.columns_internal(table_name, name, s) end |
#pg_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 248 def pg_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) # Extract the table from the insert sql. Yuck. table = sql.split(" ", 4)[2].gsub('"', '') # Try an insert with 'returning id' if available (PG >= 8.2) if supports_insert_with_returning? && id_value.nil? pk, sequence_name = *pk_and_sequence_for(table) unless pk if pk id_value = select_value("#{sql} RETURNING #{quote_column_name(pk)}") clear_query_cache #FIXME: Why now? return id_value end end # Otherwise, plain insert execute(sql, name) # Don't need to look up id_value if we already have it. # (and can't in case of non-sequence PK) unless id_value # If neither pk nor sequence name is given, look them up. unless pk || sequence_name pk, sequence_name = *pk_and_sequence_for(table) end # If a pk is given, fallback to default sequence name. # Don't fetch last insert id for a table without a pk. if pk && sequence_name ||= default_sequence_name(table, pk) id_value = last_insert_id(table, sequence_name) end end id_value end |
#pk_and_sequence_for(table) ⇒ Object
Find a table’s primary key and sequence.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 201 def pk_and_sequence_for(table) #:nodoc: # First try looking for a sequence with a dependency on the # given table's primary key. result = select(<<-end_sql, 'PK and serial sequence')[0] SELECT attr.attname, seq.relname FROM pg_class seq, pg_attribute attr, pg_depend dep, pg_namespace name, pg_constraint cons WHERE seq.oid = dep.objid AND seq.relkind = 'S' AND attr.attrelid = dep.refobjid AND attr.attnum = dep.refobjsubid AND attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1] AND cons.contype = 'p' AND dep.refobjid = '#{quote_table_name(table)}'::regclass end_sql if result.nil? or result.empty? # If that fails, try parsing the primary key's default value. # Support the 7.x and 8.0 nextval('foo'::text) as well as # the 8.1+ nextval('foo'::regclass). result = select(<<-end_sql, 'PK and custom sequence')[0] SELECT attr.attname, CASE WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN substr(split_part(def.adsrc, '''', 2), strpos(split_part(def.adsrc, '''', 2), '.')+1) ELSE split_part(def.adsrc, '''', 2) END as relname FROM pg_class t JOIN pg_attribute attr ON (t.oid = attrelid) JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum) JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1]) WHERE t.oid = '#{quote_table_name(table)}'::regclass AND cons.contype = 'p' AND def.adsrc ~* 'nextval' end_sql end [result["attname"], result["relname"]] rescue nil end |
#postgresql_version ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 108 def postgresql_version @postgresql_version ||= begin value = select_value('SELECT version()') if value =~ /PostgreSQL (\d+)\.(\d+)\.(\d+)/ ($1.to_i * 10000) + ($2.to_i * 100) + $3.to_i else 0 end end end |
#primary_key(table) ⇒ Object
368 369 370 371 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 368 def primary_key(table) pk_and_sequence = pk_and_sequence_for(table) pk_and_sequence && pk_and_sequence.first end |
#quote(value, column = nil) ⇒ Object
:nodoc:
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 436 def quote(value, column = nil) #:nodoc: return super unless column if value.kind_of?(String) && column.type == :binary "E'#{escape_bytea(value)}'" elsif value.kind_of?(String) && column.sql_type == 'xml' "xml '#{quote_string(value)}'" elsif value.kind_of?(Numeric) && column.sql_type == 'money' # Not truly string input, so doesn't require (or allow) escape string syntax. "'#{value}'" elsif value.kind_of?(String) && column.sql_type =~ /^bit/ case value when /^[01]*$/ "B'#{value}'" # Bit-string notation when /^[0-9A-F]*$/i "X'#{value}'" # Hexadecimal notation end else super end end |
#quote_column_name(name) ⇒ Object
477 478 479 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 477 def quote_column_name(name) %("#{name}") end |
#quote_table_name(name) ⇒ Object
466 467 468 469 470 471 472 473 474 475 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 466 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 |
#quoted_date(value) ⇒ Object
:nodoc:
481 482 483 484 485 486 487 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 481 def quoted_date(value) #:nodoc: if value.acts_like?(:time) && value.respond_to?(:usec) "#{super}.#{sprintf("%06d", value.usec)}" else super end end |
#recreate_database(name) ⇒ Object
343 344 345 346 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 343 def recreate_database(name) drop_database(name) create_database(name) end |
#release_savepoint ⇒ Object
165 166 167 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 165 def release_savepoint execute("RELEASE SAVEPOINT #{current_savepoint_name}") end |
#remove_index(table_name, options) ⇒ Object
:nodoc:
555 556 557 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 555 def remove_index(table_name, ) #:nodoc: execute "DROP INDEX #{index_name(table_name, )}" end |
#rename_column(table_name, column_name, new_column_name) ⇒ Object
:nodoc:
551 552 553 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 551 def rename_column(table_name, column_name, new_column_name) #:nodoc: execute "ALTER TABLE #{quote_table_name(table_name)} RENAME COLUMN #{quote_column_name(column_name)} TO #{quote_column_name(new_column_name)}" end |
#rename_table(name, new_name) ⇒ Object
496 497 498 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 496 def rename_table(name, new_name) execute "ALTER TABLE #{name} RENAME TO #{new_name}" end |
#reset_pk_sequence!(table, pk = nil, sequence = nil) ⇒ Object
Resets sequence to the max value of the table’s pk if present.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 181 def reset_pk_sequence!(table, pk = nil, sequence = nil) #:nodoc: unless pk and sequence default_pk, default_sequence = pk_and_sequence_for(table) pk ||= default_pk sequence ||= default_sequence end if pk if sequence quoted_sequence = quote_column_name(sequence) select_value <<-end_sql, 'Reset sequence' SELECT setval('#{quoted_sequence}', (SELECT COALESCE(MAX(#{quote_column_name pk})+(SELECT increment_by FROM #{quoted_sequence}), (SELECT min_value FROM #{quoted_sequence})) FROM #{quote_table_name(table)}), false) end_sql else @logger.warn "#{table} has primary key #{pk} with no default sequence" if @logger end end end |
#rollback_to_savepoint ⇒ Object
161 162 163 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 161 def rollback_to_savepoint execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}") end |
#structure_dump ⇒ Object
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 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 373 def structure_dump database = @config[:database] if database.nil? if @config[:url] =~ /\/([^\/]*)$/ database = $1 else raise "Could not figure out what database this url is for #{@config["url"]}" end end ENV['PGHOST'] = @config[:host] if @config[:host] ENV['PGPORT'] = @config[:port].to_s if @config[:port] ENV['PGPASSWORD'] = @config[:password].to_s if @config[:password] search_path = @config[:schema_search_path] search_path = "--schema=#{search_path}" if search_path @connection.connection.close begin definition = `pg_dump -i -U "#{@config[:username]}" -s -x -O #{search_path} #{database}` raise "Error dumping database" if $?.exitstatus == 1 # need to patch away any references to SQL_ASCII as it breaks the JDBC driver definition.gsub(/SQL_ASCII/, 'UNICODE') ensure reconnect! end end |
#supports_count_distinct? ⇒ Boolean
:nodoc:
153 154 155 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 153 def supports_count_distinct? #:nodoc: false end |
#supports_ddl_transactions? ⇒ Boolean
145 146 147 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 145 def supports_ddl_transactions? true end |
#supports_insert_with_returning? ⇒ Boolean
141 142 143 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 141 def supports_insert_with_returning? postgresql_version >= 80200 end |
#supports_migrations? ⇒ Boolean
Does PostgreSQL support migrations?
121 122 123 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 121 def supports_migrations? true end |
#supports_savepoints? ⇒ Boolean
149 150 151 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 149 def supports_savepoints? true end |
#supports_standard_conforming_strings? ⇒ Boolean
Does PostgreSQL support standard conforming strings?
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 126 def supports_standard_conforming_strings? # Temporarily set the client message level above error to prevent unintentional # error messages in the logs when working on a PostgreSQL database server that # does not support standard conforming strings. = self. = 'panic' # postgres-pr does not raise an exception when client_min_messages is set higher # than error and "SHOW standard_conforming_strings" fails, but returns an empty # PGresult instead. has_support = select('SHOW standard_conforming_strings').to_a[0][0] rescue false self. = has_support end |
#table_alias_length ⇒ Object
Returns the configured supported identifier length supported by PostgreSQL, or report the default of 63 on PostgreSQL 7.x.
171 172 173 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 171 def table_alias_length @table_alias_length ||= (postgresql_version >= 80000 ? select_one('SHOW max_identifier_length')['max_identifier_length'].to_i : 63) end |
#tables ⇒ Object
571 572 573 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 571 def tables @connection.tables(database_name, nil, nil, ["TABLE"]) end |
#type_to_sql(type, limit = nil, precision = nil, scale = nil) ⇒ Object
:nodoc:
559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 559 def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc: return super unless type.to_s == 'integer' if limit.nil? || limit == 4 'integer' elsif limit < 4 'smallint' else 'bigint' end end |