Thread: SERIAL columns in foreign tables

SERIAL columns in foreign tables

From
Alvaro Herrera
Date:
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"
doesnot 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"
doesnot 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



Re: SERIAL columns in foreign tables

From
Robert Haas
Date:
On Fri, Aug 17, 2012 at 10:53 AM, Alvaro Herrera
<alvherre@2ndquadrant.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