From: Elliot <yields.falsehood@gmail.com>
To: Thara Vadakkeveedu <tharagv@yahoo.com>
To: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: checking if sequence exists
Date: Fri, 15 Nov 2013 14:36:31 -0500
Message-ID: <528677BF.7060308@gmail.com> (raw)
In-Reply-To: <1384543840.72953.YahooMailNeo@web125002.mail.ne1.yahoo.com>
References: <CA+yMuNq+unyKgCrpfmmb2WK0=toMzqrx7491n=upM8Rrj3KtwQ@mail.gmail.com>
<CAKoxK+5DvJYF3tor6=kJKdfhpxoui6PAFjuhy9WzHjZbngGDPQ@mail.gmail.com>
<CA+yMuNqxZu+xZeGiD-fdC+QZK-x9+zg03X8xzDpBvQcVTncYxg@mail.gmail.com>
<1384543840.72953.YahooMailNeo@web125002.mail.ne1.yahoo.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: yields.falsehood@gmail.com, tharagv@yahoo.com
Subject: Re: checking if sequence exists
In-Reply-To: <528677BF.7060308@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox