From: | Elliot <yields(dot)falsehood(at)gmail(dot)com> |
---|---|
To: | Thara Vadakkeveedu <tharagv(at)yahoo(dot)com>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: checking if sequence exists |
Date: | 2013-11-15 19:36:31 |
Message-ID: | 528677BF.7060308@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On 2013-11-15 14:30, Thara Vadakkeveedu wrote:
> How can we find out if a particular sequence exists ? The idea is to
> check if sequence first and if it does not exist then create it...the
> goal is to do this when we deploy the application war...
> thanks
> tg
>
In psql if you set ECHO_HIDDEN you can get it to dump out its
introspection queries, like the one for \ds, which gives you a list of
sequences.
For instance,
These steps:
\set ECHO_HIDDEN 1
\ds
Yield a query like this:
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm'
THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence'
WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as "Type",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('S','s','')
AND n.nspname !~ '^pg_toast'
AND n.nspname = '<schemaname>'
and c.relname = '<sequencename>'
ORDER BY 1,2
;
From | Date | Subject | |
---|---|---|---|
Next Message | Payal Singh | 2013-11-15 19:38:50 | Re: checking if sequence exists |
Previous Message | Thara Vadakkeveedu | 2013-11-15 19:36:03 | Re: checking if sequence exists |