lib/updateable_views_inheritance/postgresql_adapter.rb
# Returns a relation's primary key and belonging sequence. If +relation+ is a table the result is its PK and sequence.
# When it is a view, PK and sequence of the table at the root of the inheritance chain are returned.
Returns a relation's primary key and belonging sequence. If +relation+ is a table the result is its PK and sequence.
When it is a view, PK and sequence of the table at the root of the inheritance chain are returned.
Returns a relation ' s primary key and belonging sequence . If + relation + is a table the result is its PK and sequence . When it is a view PK and sequence of the table at the root of the inheritance chain are returned .
def pk_and_sequence_for(relation)
          result = query(<<-end_sql, 'PK')[0]
            SELECT attr.attname
              FROM pg_attribute attr,
                   pg_constraint cons
             WHERE cons.conrelid = attr.attrelid
               AND cons.conrelid = '#{relation}'::regclass
               AND cons.contype  = 'p'
               AND attr.attnum   = ANY(cons.conkey)
          end_sql
          if result.nil? or result.empty?
            parent = parent_table(relation)
            pk_and_sequence_for(parent) if parent
          else
            [result[0], query("SELECT pg_get_serial_sequence('#{relation}', '#{result[0]}') ")[0][0]]
          end
        rescue
          nil
        end
def pk_and_sequence_for ( relation ) result = query ( <<-end_sql , 'PK' ) [ 0 ] 
            SELECT attr.attname
              FROM pg_attribute attr,
                   pg_constraint cons
             WHERE cons.conrelid = attr.attrelid
               AND cons.conrelid = ' #{ relation } '::regclass
               AND cons.contype  = 'p'
               AND attr.attnum   = ANY(cons.conkey)
           end_sql if result . nil? or result . empty? parent = parent_table ( relation ) pk_and_sequence_for ( parent ) if parent else [ result [ 0 ] , query ( "SELECT pg_get_serial_sequence('#{relation}', '#{result[0]}') " ) [ 0 ] [ 0 ] ] end rescue nil end
Returns a relation's primary key and belonging sequence.
Returns a relation ' s primary key and belonging sequence .
# log(result[0], "PK for #{relation}") {}
relation
<not_specific>