Re: BUG #15198: nextval() accepts tables/indexes when adding adefault to a column - Mailing list pgsql-bugs

From Peter Eisentraut
Subject Re: BUG #15198: nextval() accepts tables/indexes when adding adefault to a column
Date
Msg-id f0ca3887-aa58-4f55-fcc4-3d49a986e15c@2ndquadrant.com
Whole thread Raw
In response to BUG #15198: nextval() accepts tables/indexes when adding a default toa column  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #15198: nextval() accepts tables/indexes when adding adefault to a column  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: BUG #15198: nextval() accepts tables/indexes when adding a default to a column  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On 5/16/18 05:29, PG Bug reporting form wrote:
> bugtest=# CREATE TABLE demo(i int default nextval('demo') PRIMARY KEY);
> CREATE TABLE
> bugtest=# ALTER TABLE demo ADD COLUMN j int default nextval('demo_pkey');
> ALTER TABLE
> bugtest=# \d demo
>                            Table "public.demo"
>  Column |  Type   | Collation | Nullable |            Default
> --------+---------+-----------+----------+--------------------------------
>  i      | integer |           | not null | nextval('demo'::regclass)
>  j      | integer |           |          | nextval('demo_pkey'::regclass)
> Indexes:
>     "demo_pkey" PRIMARY KEY, btree (i)
> 
> bugtest=# INSERT INTO demo (i, j) VALUES (1,1);
> INSERT 0 1
> bugtest=# INSERT INTO demo (i, j) VALUES (DEFAULT, DEFAULT);
> ERROR:  42809: "demo" is not a sequence
> LOCATION:  init_sequence, sequence.c:1139

You are right that this is not optimal behavior.  I'm not sure if it's
worth fixing, however.  (Introduce a regsequence type to use in place of
regclass?)

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


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15200: Support ANSI OFFSET .. FETCH syntax with bind variables
Next
From: Peter Eisentraut
Date:
Subject: issue with updatable cursors