diff options
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/copy.c | 2 | ||||
-rw-r--r-- | src/backend/commands/sequence.c | 4 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 33 |
3 files changed, 32 insertions, 7 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 98bcb2fcf33..cd6b13c09f3 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -800,7 +800,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString) Assert(rel); /* check read-only transaction */ - if (XactReadOnly && rel->rd_backend != MyBackendId) + if (XactReadOnly && !rel->rd_islocaltemp) PreventCommandIfReadOnly("COPY FROM"); cstate = BeginCopyFrom(rel, stmt->filename, diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index fbb6489915e..c6cf44a8a8d 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -552,7 +552,7 @@ nextval_internal(Oid relid) RelationGetRelationName(seqrel)))); /* read-only transactions may only modify temp sequences */ - if (seqrel->rd_backend != MyBackendId) + if (!seqrel->rd_islocaltemp) PreventCommandIfReadOnly("nextval()"); if (elm->last != elm->cached) /* some numbers were cached */ @@ -845,7 +845,7 @@ do_setval(Oid relid, int64 next, bool iscalled) RelationGetRelationName(seqrel)))); /* read-only transactions may only modify temp sequences */ - if (seqrel->rd_backend != MyBackendId) + if (!seqrel->rd_islocaltemp) PreventCommandIfReadOnly("setval()"); /* lock page' buffer and read tuple */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index ab5ab940ade..5d64461cdaa 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -1450,13 +1450,20 @@ MergeAttributes(List *schema, List *supers, char relpersistence, errmsg("inherited relation \"%s\" is not a table", parent->relname))); /* Permanent rels cannot inherit from temporary ones */ - if (relpersistence != RELPERSISTENCE_TEMP - && RelationUsesTempNamespace(relation)) + if (relpersistence != RELPERSISTENCE_TEMP && + relation->rd_rel->relpersistence == RELPERSISTENCE_TEMP) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot inherit from temporary relation \"%s\"", parent->relname))); + /* If existing rel is temp, it must belong to this session */ + if (relation->rd_rel->relpersistence == RELPERSISTENCE_TEMP && + !relation->rd_islocaltemp) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot inherit from temporary relation of another session"))); + /* * We should have an UNDER permission flag for this, but for now, * demand that creator of a child table own the parent. @@ -5767,6 +5774,10 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, ereport(ERROR, (errcode(ERRCODE_INVALID_TABLE_DEFINITION), errmsg("constraints on temporary tables may reference only temporary tables"))); + if (!pkrel->rd_islocaltemp || !rel->rd_islocaltemp) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TABLE_DEFINITION), + errmsg("constraints on temporary tables must involve temporary tables of this session"))); break; } @@ -8905,13 +8916,27 @@ ATExecAddInherit(Relation child_rel, RangeVar *parent, LOCKMODE lockmode) ATSimplePermissions(parent_rel, ATT_TABLE); /* Permanent rels cannot inherit from temporary ones */ - if (RelationUsesTempNamespace(parent_rel) - && !RelationUsesTempNamespace(child_rel)) + if (parent_rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && + child_rel->rd_rel->relpersistence != RELPERSISTENCE_TEMP) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot inherit from temporary relation \"%s\"", RelationGetRelationName(parent_rel)))); + /* If parent rel is temp, it must belong to this session */ + if (parent_rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && + !parent_rel->rd_islocaltemp) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot inherit from temporary relation of another session"))); + + /* Ditto for the child */ + if (child_rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && + !child_rel->rd_islocaltemp) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot inherit to temporary relation of another session"))); + /* * Check for duplicates in the list of parents, and determine the highest * inhseqno already present; we'll use the next one for the new parent. |