Обсуждение: For the PG experts

Поиск
Список
Период
Сортировка

For the PG experts

От
Laurent ROCHE
Дата:
Hi,

I have posted this on the pg main list ... and as I had no sensible answers, I am trying here.
Also, it's likely someone knows the answer as you need to get this info to display it in pgAdmin !

I would like to write a request where I would get the table name and column name of a sequence. I have been looking at the sytem table and could not link the sequence from pg_class to a table (and even less to a column).

Any ideas ?
 
Have fun,
L@u
The Computing Froggy




Envoyé avec Yahoo! Mail.
Une boite mail plus intelligente.

Re: For the PG experts

От
Julius Tuskenis
Дата:
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...



Laurent ROCHE rašė:
> Hi,
>
> I have posted this on the pg main list ... and as I had no sensible 
> answers, I am trying here.
> Also, it's likely someone knows the answer as you need to get this 
> info to display it in pgAdmin !
>
> I would like to write a request where I would get the table name and 
> column name of a sequence. I have been looking at the sytem table and 
> could not link the sequence from pg_class to a table (and even less to 
> a column).
>
> Any ideas ?
>  
> Have fun,
> L@u
> The Computing Froggy
>
>
>
> ------------------------------------------------------------------------
> Envoyé avec Yahoo! Mail 
>
<http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html>.
> Une boite mail plus intelligente. 


-- 
Julius Tuskenis
Programavimo skyriaus vadovas
UAB nSoft
mob. +37068233050



Re: For the PG experts

От
Erwin Brandstetter
Дата:
On Jun 16, 3:34 pm, jul...@nsoft.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