mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
Make SPI_fnumber() reject dropped columns.
There's basically no scenario where it's sensible for this to match dropped columns, so put a test for dropped-ness into SPI_fnumber() itself, and excise the test from the small number of callers that were paying attention to the case. (Most weren't :-(.) In passing, normalize tests at call sites: always reject attnum <= 0 if we're disallowing system columns. Previously there was a mixture of "< 0" and "<= 0" tests. This makes no practical difference since SPI_fnumber() never returns 0, but I'm feeling pedantic today. Also, in the places that are actually live user-facing code and not legacy cruft, distinguish "column not found" from "can't handle system column". Per discussion with Jim Nasby; thi supersedes his original patch that just changed the behavior at one call site. Discussion: <b2de8258-c4c0-1cb8-7b97-e8538e5c975c@BlueTreble.com>
This commit is contained in:
@ -71,7 +71,7 @@ autoinc(PG_FUNCTION_ARGS)
|
||||
int32 val;
|
||||
Datum seqname;
|
||||
|
||||
if (attnum < 0)
|
||||
if (attnum <= 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
|
||||
errmsg("\"%s\" has no attribute \"%s\"",
|
||||
|
@ -67,7 +67,7 @@ insert_username(PG_FUNCTION_ARGS)
|
||||
|
||||
attnum = SPI_fnumber(tupdesc, args[0]);
|
||||
|
||||
if (attnum < 0)
|
||||
if (attnum <= 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
|
||||
errmsg("\"%s\" has no attribute \"%s\"", relname, args[0])));
|
||||
|
@ -84,9 +84,9 @@ moddatetime(PG_FUNCTION_ARGS)
|
||||
|
||||
/*
|
||||
* This is where we check to see if the field we are supposed to update
|
||||
* even exists. The above function must return -1 if name not found?
|
||||
* even exists.
|
||||
*/
|
||||
if (attnum < 0)
|
||||
if (attnum <= 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
|
||||
errmsg("\"%s\" has no attribute \"%s\"",
|
||||
|
@ -135,7 +135,7 @@ check_primary_key(PG_FUNCTION_ARGS)
|
||||
int fnumber = SPI_fnumber(tupdesc, args[i]);
|
||||
|
||||
/* Bad guys may give us un-existing column in CREATE TRIGGER */
|
||||
if (fnumber < 0)
|
||||
if (fnumber <= 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("there is no attribute \"%s\" in relation \"%s\"",
|
||||
@ -362,7 +362,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
|
||||
int fnumber = SPI_fnumber(tupdesc, args[i]);
|
||||
|
||||
/* Bad guys may give us un-existing column in CREATE TRIGGER */
|
||||
if (fnumber < 0)
|
||||
if (fnumber <= 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||
errmsg("there is no attribute \"%s\" in relation \"%s\"",
|
||||
@ -469,6 +469,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
|
||||
char *type;
|
||||
|
||||
fn = SPI_fnumber(tupdesc, args_temp[k - 1]);
|
||||
Assert(fn > 0); /* already checked above */
|
||||
nv = SPI_getvalue(newtuple, tupdesc, fn);
|
||||
type = SPI_gettype(tupdesc, fn);
|
||||
|
||||
|
@ -157,7 +157,7 @@ timetravel(PG_FUNCTION_ARGS)
|
||||
for (i = 0; i < MinAttrNum; i++)
|
||||
{
|
||||
attnum[i] = SPI_fnumber(tupdesc, args[i]);
|
||||
if (attnum[i] < 0)
|
||||
if (attnum[i] <= 0)
|
||||
elog(ERROR, "timetravel (%s): there is no attribute %s", relname, args[i]);
|
||||
if (SPI_gettypeid(tupdesc, attnum[i]) != ABSTIMEOID)
|
||||
elog(ERROR, "timetravel (%s): attribute %s must be of abstime type",
|
||||
@ -166,7 +166,7 @@ timetravel(PG_FUNCTION_ARGS)
|
||||
for (; i < argc; i++)
|
||||
{
|
||||
attnum[i] = SPI_fnumber(tupdesc, args[i]);
|
||||
if (attnum[i] < 0)
|
||||
if (attnum[i] <= 0)
|
||||
elog(ERROR, "timetravel (%s): there is no attribute %s", relname, args[i]);
|
||||
if (SPI_gettypeid(tupdesc, attnum[i]) != TEXTOID)
|
||||
elog(ERROR, "timetravel (%s): attribute %s must be of text type",
|
||||
|
Reference in New Issue
Block a user