# File lib/jdbc_adapter/jdbc_postgre.rb, line 122
    def pk_and_sequence_for(table)
      # First try looking for a sequence with a dependency on the
      # given table's primary key.
        result = select("SELECT attr.attname AS nm, name.nspname AS nsp, seq.relname AS rel\nFROM pg_class      seq,\npg_attribute  attr,\npg_depend     dep,\npg_namespace  name,\npg_constraint cons\nWHERE seq.oid           = dep.objid\nAND seq.relnamespace  = name.oid\nAND seq.relkind       = 'S'\nAND attr.attrelid     = dep.refobjid\nAND attr.attnum       = dep.refobjsubid\nAND attr.attrelid     = cons.conrelid\nAND attr.attnum       = cons.conkey[1]\nAND cons.contype      = 'p'\nAND dep.refobjid      = '\#{table}'::regclass\n", 'PK and serial sequence')[0]

        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).
          # TODO: assumes sequence is in same schema as table.
          result = select("SELECT attr.attname AS nm, name.nspname AS nsp, split_part(def.adsrc, '\\\\\\'', 2) AS rel\nFROM pg_class       t\nJOIN pg_namespace   name ON (t.relnamespace = name.oid)\nJOIN pg_attribute   attr ON (t.oid = attrelid)\nJOIN pg_attrdef     def  ON (adrelid = attrelid AND adnum = attnum)\nJOIN pg_constraint  cons ON (conrelid = adrelid AND adnum = conkey[1])\nWHERE t.oid = '\#{table}'::regclass\nAND cons.contype = 'p'\nAND def.adsrc ~* 'nextval'\n", 'PK and custom sequence')[0]
        end
        # check for existence of . in sequence name as in public.foo_sequence.  if it does not exist, join the current namespace
        result['rel']['.'] ? [result['nm'], result['rel']] : [result['nm'], "#{result['nsp']}.#{result['rel']}"]
      rescue
        nil
      end