Adjust COPY FREEZE error message to be more accurate and consistent.

Per suggestions from Noah and Tom.
This commit is contained in:
Bruce Momjian 2013-02-02 12:56:14 -05:00
parent f4987049ef
commit e8ae019661
2 changed files with 28 additions and 32 deletions

View File

@ -1996,6 +1996,7 @@ CopyFrom(CopyState cstate)
hi_options |= HEAP_INSERT_SKIP_FSM;
if (!XLogIsNeeded())
hi_options |= HEAP_INSERT_SKIP_WAL;
}
/*
* Optimize if new relfilenode was created in this subxact or
@ -2013,19 +2014,14 @@ CopyFrom(CopyState cstate)
(ERRCODE_INVALID_TRANSACTION_STATE,
errmsg("cannot perform FREEZE because of prior transaction activity")));
if (cstate->rel->rd_createSubid == GetCurrentSubTransactionId() ||
cstate->rel->rd_newRelfilenodeSubid == GetCurrentSubTransactionId())
if (cstate->rel->rd_createSubid != GetCurrentSubTransactionId() &&
cstate->rel->rd_newRelfilenodeSubid != GetCurrentSubTransactionId())
ereport(ERROR,
(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
errmsg("cannot perform FREEZE because the table was not created or truncated in the current subtransaction")));
hi_options |= HEAP_INSERT_FROZEN;
else
ereport(ERROR,
(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
errmsg("cannot perform FREEZE because of transaction activity after table creation or truncation")));
}
}
else if (cstate->freeze)
ereport(ERROR,
(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
errmsg("cannot perform FREEZE because the table was not created or truncated in the current transaction")));
/*
* We need a ResultRelInfo so we can use the regular executor's

View File

@ -334,12 +334,12 @@ SELECT * FROM vistest;
COMMIT;
TRUNCATE vistest;
COPY vistest FROM stdin CSV FREEZE;
ERROR: cannot perform FREEZE because the table was not created or truncated in the current transaction
ERROR: cannot perform FREEZE because the table was not created or truncated in the current subtransaction
BEGIN;
TRUNCATE vistest;
SAVEPOINT s1;
COPY vistest FROM stdin CSV FREEZE;
ERROR: cannot perform FREEZE because of transaction activity after table creation or truncation
ERROR: cannot perform FREEZE because the table was not created or truncated in the current subtransaction
COMMIT;
BEGIN;
INSERT INTO vistest VALUES ('z');
@ -347,7 +347,7 @@ SAVEPOINT s1;
TRUNCATE vistest;
ROLLBACK TO SAVEPOINT s1;
COPY vistest FROM stdin CSV FREEZE;
ERROR: cannot perform FREEZE because the table was not created or truncated in the current transaction
ERROR: cannot perform FREEZE because the table was not created or truncated in the current subtransaction
COMMIT;
CREATE FUNCTION truncate_in_subxact() RETURNS VOID AS
$$