Re: Setting Sequence Values

From: "Gregory Williamson" <Gregory(dot)Williamson(at)digitalglobe(dot)com>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: "Martin" <martin(at)cornhobble(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Setting Sequence Values
Date: 2007-12-22 04:24:43
Message-ID: 8B319E5A30FF4A48BE7EEAAF609DB233015E3129@COMAIL01.digitalglobe.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joshua Drake shaped the aether to say:
>
> Shout out to AndrewSN for this one (although I was almost there when he
> pasted it ;)):
>
> SELECT c1.relname AS sequencename, n.nspname AS schema,
> c2.relname AS tablename, a.attname AS columnname
> FROM pg_class c1
> JOIN pg_depend d ON (d.objid=c1.oid)
> JOIN pg_class c2 ON (d.refobjid=c2.oid)
> JOIN pg_attribute a ON (a.attrelid=c2.oid AND a.attnum=d.refobjsubid)
> JOIN pg_namespace n ON (n.oid=c2.relnamespace)
> WHERE c1.relkind='S'
> AND d.classid='pg_class'::regclass
> AND d.refclassid='pg_class'::regclass
> AND d.refobjsubid > 0
> AND d.deptype='a';
>
> sequencename | schema | tablename | columnname
> - --------------+--------+-----------+------------
> foo_id_seq | public | foo | id
> (1 row)
>
> - From there, scripting should be easy.

A thing of beauty ! Is it portable or tied to certain versions ? (not familiar enough with system tables and changes therein to have my own opinion)

Greg W.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-12-22 04:56:55 Re: Setting Sequence Values
Previous Message Martin 2007-12-22 04:13:18 Re: Setting Sequence Values