Re: Show sequences owned by

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Show sequences owned by
Date: 2011-11-04 14:37:50
Message-ID: CABUevEw1h0zmD4RyUc=+JPQ582+w-Yif8H4crkWi32jgm2LNzQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 4, 2011 at 15:29, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Magnus Hagander (magnus(at)hagander(dot)net) wrote:
>> If there is noone owning it at all, it just falls through the if/else
>> block and ignores it if that happens (PQntuples() returns 0).
>
> Ah, right, but 'result' is still non-zero, ok.

Yes, that's a regular libpq result set...

>> Is there really a case for multiple sequences to own it? How would you
>> go about making that happen? ALTER SEQUENCE.. OWNED BY.. only takes
>> one table, afaics?
>
> I just noticed it was pulling from pg_depend and we could be creating
> multiple dependencies on a single sequence by having two tables use it
> as a default value.  If that situation doesn't cause a problem for this,
> then that's fine. :)  Couldn't remember if we distinguished 'owned by'
> from 'dependend upon' for seqeunces.

I tried that now to be sure, and to confirm, this is the scenario:
CREATE TABLE seqtest (a SERIAL PRIMARY KEY);
CREATE TABLE seqtest2 (a int NOT NULL DEFAULT
nextval('seqtest_a_seq'::regclass);

In this case, we end up with just one entry in pg_depend, which refers
to seqtest.a.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-11-04 14:40:16 Re: Show sequences owned by
Previous Message Tom Lane 2011-11-04 14:34:46 Re: IDLE in transaction introspection