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