pgsql: Identity columns

Started by Peter Eisentrautover 9 years ago5 messagescomitters
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrytests failedCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t204093
psql -h localhost -U postgres

Built from patchset v4 (message #4), July 29, 2026 at 01:04 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t204093_4 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t204093_4 && git checkout t204093_4

Patchset v4 (message #4) is on t204093_4

Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

Identity columns

This is the SQL standard-conforming variant of PostgreSQL's serial
columns. It fixes a few usability issues that serial columns have:

- CREATE TABLE / LIKE copies default but refers to same sequence
- cannot add/drop serialness with ALTER TABLE
- dropping default does not drop sequence
- need to grant separate privileges to sequence
- other slight weirdnesses because serial is some kind of special macro

Reviewed-by: Vitaly Burovoy <vitaly.burovoy@gmail.com>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/3217327053638085d24dd4d276e7c1f7ac2c4c6b

Modified Files
--------------
doc/src/sgml/catalogs.sgml | 11 +
doc/src/sgml/information_schema.sgml | 11 +-
doc/src/sgml/ref/alter_table.sgml | 47 +++-
doc/src/sgml/ref/copy.sgml | 7 +
doc/src/sgml/ref/create_table.sgml | 65 ++++-
doc/src/sgml/ref/insert.sgml | 41 +++
src/backend/access/common/tupdesc.c | 6 +
src/backend/catalog/dependency.c | 7 +
src/backend/catalog/genbki.pl | 7 +-
src/backend/catalog/heap.c | 15 +-
src/backend/catalog/index.c | 1 +
src/backend/catalog/information_schema.sql | 17 +-
src/backend/catalog/pg_depend.c | 52 ++--
src/backend/catalog/sql_features.txt | 12 +-
src/backend/commands/sequence.c | 101 +++++--
src/backend/commands/tablecmds.c | 295 ++++++++++++++++++-
src/backend/executor/execExpr.c | 12 +
src/backend/executor/execExprInterp.c | 23 ++
src/backend/nodes/copyfuncs.c | 23 ++
src/backend/nodes/equalfuncs.c | 18 ++
src/backend/nodes/nodeFuncs.c | 11 +
src/backend/nodes/outfuncs.c | 9 +
src/backend/nodes/readfuncs.c | 1 +
src/backend/parser/analyze.c | 2 +
src/backend/parser/gram.y | 134 ++++++++-
src/backend/parser/parse_utilcmd.c | 360 +++++++++++++++++++-----
src/backend/rewrite/rewriteHandler.c | 56 +++-
src/backend/utils/adt/ruleutils.c | 8 +
src/backend/utils/cache/lsyscache.c | 32 +++
src/backend/utils/cache/relcache.c | 1 +
src/backend/utils/errcodes.txt | 1 +
src/bin/pg_dump/pg_dump.c | 95 ++++++-
src/bin/pg_dump/pg_dump.h | 3 +
src/bin/pg_dump/t/002_pg_dump.pl | 87 ++++++
src/bin/psql/describe.c | 27 +-
src/bin/psql/tab-complete.c | 18 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/dependency.h | 8 +-
src/include/catalog/pg_attribute.h | 24 +-
src/include/catalog/pg_class.h | 2 +-
src/include/commands/sequence.h | 2 +
src/include/executor/execExpr.h | 8 +
src/include/nodes/nodes.h | 1 +
src/include/nodes/parsenodes.h | 27 +-
src/include/nodes/primnodes.h | 14 +
src/include/parser/kwlist.h | 2 +
src/include/utils/lsyscache.h | 1 +
src/test/regress/expected/create_table_like.out | 47 ++++
src/test/regress/expected/identity.out | 322 +++++++++++++++++++++
src/test/regress/expected/sequence.out | 4 +-
src/test/regress/expected/truncate.out | 30 ++
src/test/regress/parallel_schedule | 5 +
src/test/regress/serial_schedule | 1 +
src/test/regress/sql/create_table_like.sql | 14 +
src/test/regress/sql/identity.sql | 192 +++++++++++++
src/test/regress/sql/sequence.sql | 2 +-
src/test/regress/sql/truncate.sql | 18 ++
57 files changed, 2140 insertions(+), 202 deletions(-)

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: pgsql: Identity columns

Peter Eisentraut <peter_e@gmx.net> writes:

Identity columns

This commit is causing a compiler warning for me:

tablecmds.c: In function 'ATExecSetIdentity':
tablecmds.c:5936: warning: 'address.objectSubId' may be used uninitialized in this function
tablecmds.c:5936: warning: 'address.objectId' may be used uninitialized in this function

I'm not sure why it's not complaining about all three fields, because
AFAICS, the function returns a totally undefined ObjectAddress when
generatedEl is not set. What is the intention there? (If the function
were adequately documented, maybe I could divine that for myself, but
heaven help the reader who would like to know what this function is
supposed to do.)

regards, tom lane

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#2)
Re: pgsql: Identity columns

On 4/6/17 10:24, Tom Lane wrote:

This commit is causing a compiler warning for me:

tablecmds.c: In function 'ATExecSetIdentity':
tablecmds.c:5936: warning: 'address.objectSubId' may be used uninitialized in this function
tablecmds.c:5936: warning: 'address.objectId' may be used uninitialized in this function

I'm not sure why it's not complaining about all three fields, because
AFAICS, the function returns a totally undefined ObjectAddress when
generatedEl is not set.

Yeah, that was an oversight. It's depressing that not more compilers
warn about an obvious case like this. I have pushed a fix.

What is the intention there? (If the function
were adequately documented, maybe I could divine that for myself, but
heaven help the reader who would like to know what this function is
supposed to do.)

Added some comments, too.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#4David Rowley
dgrowleyml@gmail.com
In reply to: Peter Eisentraut (#1)
Re: pgsql: Identity columns

On 7 April 2017 at 00:44, Peter Eisentraut <peter_e@gmx.net> wrote:

Identity columns

This is the SQL standard-conforming variant of PostgreSQL's serial
columns. It fixes a few usability issues that serial columns have:

- CREATE TABLE / LIKE copies default but refers to same sequence
- cannot add/drop serialness with ALTER TABLE
- dropping default does not drop sequence
- need to grant separate privileges to sequence
- other slight weirdnesses because serial is some kind of special macro

Attached is a small patch which fixes up a warning for compilers not
smart enough to know the elog(ERROR) does not return.

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

t204093_4
identity_columns_warning_fix.patchapplication/octet-stream; name=identity_columns_warning_fix.patchDownload+6-4
#5Peter Eisentraut
peter_e@gmx.net
In reply to: David Rowley (#4)
Re: pgsql: Identity columns

On 4/6/17 23:13, David Rowley wrote:

On 7 April 2017 at 00:44, Peter Eisentraut <peter_e@gmx.net> wrote:

Identity columns

This is the SQL standard-conforming variant of PostgreSQL's serial
columns. It fixes a few usability issues that serial columns have:

- CREATE TABLE / LIKE copies default but refers to same sequence
- cannot add/drop serialness with ALTER TABLE
- dropping default does not drop sequence
- need to grant separate privileges to sequence
- other slight weirdnesses because serial is some kind of special macro

Attached is a small patch which fixes up a warning for compilers not
smart enough to know the elog(ERROR) does not return.

fixed

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers