Обсуждение: pg_dump versus defaults on foreign tables

Поиск
Список
Период
Сортировка

pg_dump versus defaults on foreign tables

От
Tom Lane
Дата:
While fooling with the issue of serial columns for foreign tables,
I noticed that pg_dump will sometimes try to restore a default
expression with a command like this:

ALTER TABLE ONLY rem ALTER COLUMN f1 SET DEFAULT nextval('rem_f1_seq'::regclass);

which when applied to a foreign table gets you

ERROR:  "rem" is a foreign table
HINT:  Use ALTER FOREIGN TABLE instead.

Now, I suppose we could kluge up pg_dump to emit ALTER FOREIGN TABLE
instead, but I'd like to object to this degree of anal retentivity.
There is *no* good reason to refuse this command, and plenty of
precedent in favor of being laxer.  Most ALTER TABLE variants have
historically allowed any relation type for which the action is sensible.
As an example, three lines earlier in this same dump file I find

ALTER TABLE public.rem_f1_seq OWNER TO postgres;

for which we are not bleating that you have to use ALTER SEQUENCE
instead (and we'd better not start, since this usage is well embedded
in existing dump files).

Comments?
        regards, tom lane



Re: pg_dump versus defaults on foreign tables

От
Josh Berkus
Дата:
Tom,

> Comments?

I personally think that FOREIGN should be optional on most commands
where ambiguity is unlikely.  In addition to ALTER, there's no
particularly good reason why "DROP TABLE myforeigntable" doesn't work.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com



Re: pg_dump versus defaults on foreign tables

От
Tom Lane
Дата:
Josh Berkus <josh@agliodbs.com> writes:
>> Comments?

> I personally think that FOREIGN should be optional on most commands
> where ambiguity is unlikely.  In addition to ALTER, there's no
> particularly good reason why "DROP TABLE myforeigntable" doesn't work.

Well, it's certainly bizarre that we allow ALTER TABLE to work for most
non-table relation types (eg views, sequences) but specifically exclude
foreign tables, which after all are *called* tables.  So I think that's
just plain wrong.

I'm less excited about changing the DROP case, because there is
precedent extending way back for being anal about that case, eg
we do this at least as far back as 7.4:

regression=# create sequence s1;
CREATE SEQUENCE
regression=# drop table s1;
ERROR:  "s1" is not a table
HINT:  Use DROP SEQUENCE to remove a sequence.

I'm not against being laxer about DROP, but it ought to be a
thought-through change that considers what to do for all relation types
not just foreign tables.  In particular, should it follow the precedent
of ALTER TABLE that we allow "ALTER TABLE" on non-tables but if you use
another spelling such as "ALTER SEQUENCE" then it has to match the
relation type?

In any case, that restriction isn't breaking pg_dump so I don't feel
a need to change it during beta.
        regards, tom lane



Re: pg_dump versus defaults on foreign tables

От
Josh Berkus
Дата:
> In any case, that restriction isn't breaking pg_dump so I don't feel
> a need to change it during beta.

Sure.  Maybe put it on the stack for 9.4.


-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com