From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ken Tanzer <ken.tanzer@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Primary key data type: integer vs identity
Date: Fri, 19 Apr 2019 14:41:57 -0700
Message-ID: <e151f442-364d-c91b-2374-fd4a61fbe65b@aklaver.com> (raw)
In-Reply-To: <CAD3a31WTVBL7o41FpqQB-jAiBgSyf+NVt7Oc5zmpJ7rBFZA9=w@mail.gmail.com>
References: <alpine.LNX.2.20.1904191050120.24219@salmo.appl-ecosys.com>
<c1df337c-8819-711b-496e-459e7fb88408@aklaver.com>
<alpine.LNX.2.20.1904191112120.24219@salmo.appl-ecosys.com>
<b0da4cc6-be57-ddaf-f762-ac4455569417@aklaver.com>
<CAD3a31VyBMjZUM7aXLfCEdkP_gQ4Agw9-vMFm6nB_eV7sOa3OA@mail.gmail.com>
<4d387c8e-a261-0734-a10f-dfde7ce538f0@aklaver.com>
<CAD3a31UV8VxLWLFfDop4W_PUyMrKf6RGsQF7XkpdpV3Xc=sARw@mail.gmail.com>
<2752f2d1-2cec-1df4-21f7-b0b004f8e500@aklaver.com>
<CAD3a31W=QmK0H2vfcfoAnJwUhW1AtK9bpie2kb_EpZLmh2VoWA@mail.gmail.com>
<47f1fa10-fb71-0f58-9dcf-c5083680059a@aklaver.com>
<CAD3a31WTVBL7o41FpqQB-jAiBgSyf+NVt7Oc5zmpJ7rBFZA9=w@mail.gmail.com>
On 4/19/19 2:31 PM, Ken Tanzer wrote:
> On Fri, Apr 19, 2019 at 1:39 PM Adrian Klaver <adrian.klaver@aklaver.com
>
> Thanks, though I don't see what this shows, since there were not
> separate users involved. So I loaded up a copy of 11.2, and discovered
Well the table was created by one user and the serial was changed to
IDENTITY by another.
> that you actually can't change the ownership of a sequence created by
> serial.
>
> ag_tz_test=# ALTER SEQUENCE t_serial_id_seq OWNER TO develop;
> ERROR: cannot change owner of sequence "t_serial_id_seq"
> DETAIL: Sequence "t_serial_id_seq" is linked to table "t_serial".
That is covered here:
https://www.postgresql.org/docs/11/sql-altersequence.html
"OWNED BY table_name.column_name
...
The specified table must have the same owner and be in the same schema
as the sequence. ..."
Which to me means the opposite is true also.
Though you can:
" Specifying OWNED BY NONE removes any existing association, making
the sequence “free-standing”.
"
>
> I also missed the part in the article where it talks about assigning
> ownership to the column. In psql, it's easy to miss because a \ds (or
> \ds+) (as opposed to a \d) shows the user that owns the sequence, not a
> column:
>
>
> test=# \ds+
> List of relations
> Schema | Name | Type | Owner | Size | Description
> --------+-------------------+----------+-------+------------+-------------
> public | t_serial_id_seq | sequence | u1 | 8192 bytes |
>
> Whereas if you look at \d it shows the column:
>
>
> test=# \d+ t_serial_id_seq
> Sequence "public.t_serial_id_seq"
> Type | Start | Minimum | Maximum | Increment | Cycles? | Cache
> ---------+-------+---------+------------+-----------+---------+-------
> integer | 1 | 1 | 2147483647 | 1 | no | 1
> Owned by: public.t_serial.id <http://public.t_serial.id;
>
> (Side note: it is surprising that the Size and Description don't show up
> with \d+. I always thought that a \d+ was the best way to get all the
> detail on an object.)
>
> But even if you drop the default on the column, it doesn't seem like you
> can change the sequence's owner:
>
> test=# ALTER TABLE t_serial ALTER COLUMN id DROP DEFAULT;
> ALTER TABLE
> test=# alter sequence t_serial_id_seq OWNER TO u2;
> ERROR: cannot change owner of sequence "t_serial_id_seq"
> DETAIL: Sequence "t_serial_id_seq" is linked to table "t_serial".
>
> Although you can drop it:
>
> DROP SEQUENCE t_serial_id_seq;
> DROP SEQUENCE
>
> Anyhoo, I've learned a bit more today, and thanks for your help!
>
> Cheers,
> Ken
>
>
>
> --
> AGENCY Software
> A Free Software data system
> By and for non-profits
> /http://agency-software.org//
> /https://demo.agency-software.org/client/
> ken.tanzer@agency-software.org <mailto:ken.tanzer@agency-software.org>
> (253) 245-3801
>
> Subscribe to the mailing list
> <mailto:agency-general-request@lists.sourceforge.net?body=subscribe> to
> learn more about AGENCY or
> follow the discussion.
--
Adrian Klaver
adrian.klaver@aklaver.com
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, ken.tanzer@gmail.com
Subject: Re: Primary key data type: integer vs identity
In-Reply-To: <e151f442-364d-c91b-2374-fd4a61fbe65b@aklaver.com>
References: <alpine.LNX.2.20.1904191050120.24219@salmo.appl-ecosys.com> <c1df337c-8819-711b-496e-459e7fb88408@aklaver.com> <alpine.LNX.2.20.1904191112120.24219@salmo.appl-ecosys.com> <b0da4cc6-be57-ddaf-f762-ac4455569417@aklaver.com> <CAD3a31VyBMjZUM7aXLfCEdkP_gQ4Agw9-vMFm6nB_eV7sOa3OA@mail.gmail.com> <4d387c8e-a261-0734-a10f-dfde7ce538f0@aklaver.com> <CAD3a31UV8VxLWLFfDop4W_PUyMrKf6RGsQF7XkpdpV3Xc=sARw@mail.gmail.com> <2752f2d1-2cec-1df4-21f7-b0b004f8e500@aklaver.com> <CAD3a31W=QmK0H2vfcfoAnJwUhW1AtK9bpie2kb_EpZLmh2VoWA@mail.gmail.com> <47f1fa10-fb71-0f58-9dcf-c5083680059a@aklaver.com> <CAD3a31WTVBL7o41FpqQB-jAiBgSyf+NVt7Oc5zmpJ7rBFZA9=w@mail.gmail.com> <e151f442-364d-c91b-2374-fd4a61fbe65b@aklaver.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