Re: For the PG experts

From: Erwin Brandstetter <brsaweda(at)gmail(dot)com>
To: pgadmin-support(at)postgresql(dot)org
Subject: Re: For the PG experts
Date: 2008-06-28 15:50:23
Message-ID: c5c63a96-e4c8-474f-9fa1-dedcd8a4c940@w7g2000hsa.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

On Jun 16, 3:34 pm, jul(dot)(dot)(dot)(at)nsoft(dot)lt (Julius Tuskenis) wrote:
> Hi Laurent.
>
> As I understand where is no direct link between sequence and the table
> column. You should see pg_attrdef table.
> Query SELECT  pg_get_expr(adbin,adrelid)  FROM pg_attrdef; will return
> you all default values of the columns. Among them you will find
> nextval('your_sequence'::regclass).
>
> Hope that helps...

Right, or more precisely, to get the default for your primary key
column
myschema.mytab.mycol
use:

SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid)
FROM pg_catalog.pg_attrdef d
JOIN pg_catalog.pg_attribute a ON d.adrelid = a.attrelid AND d.adnum
= a.attnum
JOIN pg_catalog.pg_class c ON c.oid = a.attrelid
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'myschema' AND c.relname = 'mytab' AND a.attname =
'mycol'
ORDER BY a.attnum

Gives you something like:
nextval('mytab_mycol_seq'::regclass)
The quotet part being the sequence in use.

Where do I get this? Try psql -E and work from there. (Shows the
queries psql uses to retrieve its data.)

But all of this is hardly on topic here. Please turn to
pgsql.admin (pgsql-admin(at)postgresql(dot)org)
or
pgsql.general (pgsql-general(at)postgresql(dot)org)

Regards
Erwin

In response to

Browse pgadmin-support by date

  From Date Subject
Next Message Ryan Daniels 2008-06-29 17:06:12 Re: Wish List Request: Tabbed SQL Query Window
Previous Message Asdrubal Corales 2008-06-26 16:52:39 Re: Instalación