summaryrefslogtreecommitdiff
path: root/src/backend/commands/sequence.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-05-15 19:03:29 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2013-05-15 19:03:29 -0400
commitb14206862278347a379f2bb72d92d16fb9dcea45 (patch)
tree2459ffad8b3842fa1314a3cd109f11013e065aa8 /src/backend/commands/sequence.c
parenta2a480af889b5d9abce4181e49b6398f0e24b808 (diff)
Allow CREATE FOREIGN TABLE to include SERIAL columns.
The behavior is that the required sequence is created locally, which is appropriate because the default expression will be evaluated locally. Per gripe from Brad Nicholson that this case was refused with a confusing error message. We could have improved the error message but it seems better to just allow the case. Also, remove ALTER TABLE's arbitrary prohibition against being applied to foreign tables, which was pretty inconsistent considering we allow it for views, sequences, and other relation types that aren't even called tables. This is needed to avoid breaking pg_dump, which sometimes emits column defaults using separate ALTER TABLE commands. (I think this can happen even when the default is not associated with a sequence, so that was a pre-existing bug once we allowed column defaults for foreign tables.)
Diffstat (limited to 'src/backend/commands/sequence.c')
-rw-r--r--src/backend/commands/sequence.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index ff855d60e5d..49e409a5eed 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -1440,11 +1440,12 @@ process_owned_by(Relation seqrel, List *owned_by)
rel = makeRangeVarFromNameList(relname);
tablerel = relation_openrv(rel, AccessShareLock);
- /* Must be a regular table */
- if (tablerel->rd_rel->relkind != RELKIND_RELATION)
+ /* Must be a regular or foreign table */
+ if (!(tablerel->rd_rel->relkind == RELKIND_RELATION ||
+ tablerel->rd_rel->relkind == RELKIND_FOREIGN_TABLE))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("referenced relation \"%s\" is not a table",
+ errmsg("referenced relation \"%s\" is not a table or foreign table",
RelationGetRelationName(tablerel))));
/* We insist on same owner and schema */