SERIAL columns in foreign tables

Lists: pgsql-hackers
From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: SERIAL columns in foreign tables
Date: 2012-08-17 14:53:21
Message-ID: 1345214955-sup-3970@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

While working on the NOT NULL constraint stuff, I noticed that if you're
creating a foreign table with a SERIAL column, it bleats like this:

CREATE FOREIGN TABLE ft1 (c1 serial) SERVER sc;
ERROR: default values on foreign tables are not supported

Note that it's talking about a default value, which the user never
explicitely defined. So it's obviously about the internally defined
default value for nextval. Now, the reason I noticed is because since
the column is also marked NOT NULL, and constraints are also disallowed
in foreign tables (and apparently checked earlier than defaults), then
the error message is changed:

*** /pgsql/source/notnull-constraint/src/test/regress/expected/foreign_data.out 2012-08-14 18:04:51.589535046 -0400
--- /home/alvherre/Code/pgsql/build/notnull-constraint/src/test/regress/results/foreign_data.out 2012-08-16 17:49:17.208314737 -0400
***************
*** 665,671 ****
CREATE FOREIGN TABLE ft1 () SERVER no_server; -- ERROR
ERROR: server "no_server" does not exist
CREATE FOREIGN TABLE ft1 (c1 serial) SERVER sc; -- ERROR
! ERROR: default values on foreign tables are not supported
CREATE FOREIGN TABLE ft1 () SERVER s0 WITH OIDS; -- ERROR
ERROR: syntax error at or near "WITH OIDS"
LINE 1: CREATE FOREIGN TABLE ft1 () SERVER s0 WITH OIDS;
--- 665,671 ----
CREATE FOREIGN TABLE ft1 () SERVER no_server; -- ERROR
ERROR: server "no_server" does not exist
CREATE FOREIGN TABLE ft1 (c1 serial) SERVER sc; -- ERROR
! ERROR: constraints on foreign tables are not supported
CREATE FOREIGN TABLE ft1 () SERVER s0 WITH OIDS; -- ERROR
ERROR: syntax error at or near "WITH OIDS"
LINE 1: CREATE FOREIGN TABLE ft1 () SERVER s0 WITH OIDS;

I guess one very simple solution to this problem would be to just adjust
the expected output for foreign tables.

However I'm wondering if it'd be better to tweak the code to explicitely
check for SERIAL/BIGSERIAL instead of letting it error out in internal
conditions. The way it currently is, it seems a bit user-unfriendly to
me.

Thoughts?

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SERIAL columns in foreign tables
Date: 2012-08-20 18:55:53
Message-ID: CA+TgmobJ1F4kVju5O7hBy6EJL0NztxJUAcd0G-o5DY8p439sZA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Aug 17, 2012 at 10:53 AM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
> However I'm wondering if it'd be better to tweak the code to explicitely
> check for SERIAL/BIGSERIAL instead of letting it error out in internal
> conditions. The way it currently is, it seems a bit user-unfriendly to
> me.

I don't think the current error message is horrible, but I don't
object to improving it, either.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company