Sha256: 291150ab88eea48aef7832a8a3fd0019d5941e882c97b66a64d4ea6863ffa7bf
Contents?: true
Size: 1.78 KB
Versions: 19
Compression:
Stored size: 1.78 KB
Contents
module ActiveRecord module ConnectionAdapters class PostgreSQLAdapter < AbstractAdapter # This mightn't be in Core, but count(distinct x,y) doesn't work for me def supports_count_distinct? #:nodoc: false end def concat(*columns) columns = columns.map { |c| "CAST(#{c} AS varchar)" } "(#{columns.join('||')})" end # Executes an INSERT query and returns the new record's ID def 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? pk, sequence_name = *pk_and_sequence_for(table) unless pk if pk quoted_pk = if pk.is_a?(Array) pk.map { |col| quote_column_name(col) }.join(CompositePrimaryKeys::ID_SEP) else quote_column_name(pk) end id = select_value("#{sql} RETURNING #{quoted_pk}") clear_query_cache return id end end # Otherwise, insert then grab last_insert_id. if insert_id = super insert_id else # 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) last_insert_id(table, sequence_name) end end end end end end
Version data entries
19 entries across 19 versions & 2 rubygems