aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-11-08 13:11:15 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-11-08 13:11:26 -0500
commit6d30fb1f75a57d80f80e27770d39d88f8aa32d28 (patch)
tree056042db35fa8ad69957dd54dda3c5dcaaa62d7c /src
parent36ac6d0e793087153a452df6502d0ef32a780db6 (diff)
downloadpostgresql-6d30fb1f75a57d80f80e27770d39d88f8aa32d28.tar.gz
postgresql-6d30fb1f75a57d80f80e27770d39d88f8aa32d28.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/backend/executor/spi.c3
-rw-r--r--src/backend/utils/adt/tsvector_op.c1
-rw-r--r--src/pl/plperl/plperl.c7
-rw-r--r--src/pl/tcl/pltcl.c11
-rw-r--r--src/test/regress/regress.c9
5 files changed, 15 insertions, 16 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 38767ae4ced..8e650bc4123 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -824,7 +824,8 @@ SPI_fnumber(TupleDesc tupdesc, const char *fname)
for (res = 0; res < tupdesc->natts; res++)
{
- if (namestrcmp(&tupdesc->attrs[res]->attname, fname) == 0)
+ if (namestrcmp(&tupdesc->attrs[res]->attname, fname) == 0 &&
+ !tupdesc->attrs[res]->attisdropped)
return res + 1;
}
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c
index ad5a254c57e..0e9ae5ff9cf 100644
--- a/src/backend/utils/adt/tsvector_op.c
+++ b/src/backend/utils/adt/tsvector_op.c
@@ -2242,6 +2242,7 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column)
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("tsvector column \"%s\" does not exist",
trigger->tgargs[0])));
+ /* This will effectively reject system columns, so no separate test: */
if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, tsvector_attr_num),
TSVECTOROID))
ereport(ERROR,
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 4d993e7371d..461986cda31 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1062,11 +1062,16 @@ plperl_build_tuple_result(HV *perlhash, TupleDesc td)
char *key = hek2cstr(he);
int attn = SPI_fnumber(td, key);
- if (attn <= 0 || td->attrs[attn - 1]->attisdropped)
+ if (attn == SPI_ERROR_NOATTRIBUTE)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("Perl hash contains nonexistent column \"%s\"",
key)));
+ if (attn <= 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot set system attribute \"%s\"",
+ key)));
values[attn - 1] = plperl_sv_to_datum(val,
td->attrs[attn - 1]->atttypid,
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 3e52113ee25..20809102efb 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -603,6 +603,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp)
* leave this code as DString - it's only executed once per session
************************************************************/
fno = SPI_fnumber(SPI_tuptable->tupdesc, "modsrc");
+ Assert(fno > 0);
Tcl_DStringInit(&unknown_src);
@@ -1260,12 +1261,6 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, pltcl_call_state *call_state,
ret_name)));
/************************************************************
- * Ignore dropped columns
- ************************************************************/
- if (tupdesc->attrs[attnum - 1]->attisdropped)
- continue;
-
- /************************************************************
* Lookup the attribute type's input function
************************************************************/
getTypeInputInfo(tupdesc->attrs[attnum - 1]->atttypid,
@@ -3077,10 +3072,6 @@ pltcl_build_tuple_result(Tcl_Interp *interp, Tcl_Obj **kvObjv, int kvObjc,
errmsg("cannot set system attribute \"%s\"",
fieldName)));
- /* Ignore dropped attributes */
- if (call_state->ret_tupdesc->attrs[attn - 1]->attisdropped)
- continue;
-
values[attn - 1] = utf_e2u(Tcl_GetString(kvObjv[i + 1]));
}
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index e7826a4513b..119a59ab073 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -523,11 +523,12 @@ ttdummy(PG_FUNCTION_ARGS)
for (i = 0; i < 2; i++)
{
attnum[i] = SPI_fnumber(tupdesc, args[i]);
- if (attnum[i] < 0)
- elog(ERROR, "ttdummy (%s): there is no attribute %s", relname, args[i]);
+ if (attnum[i] <= 0)
+ elog(ERROR, "ttdummy (%s): there is no attribute %s",
+ relname, args[i]);
if (SPI_gettypeid(tupdesc, attnum[i]) != INT4OID)
- elog(ERROR, "ttdummy (%s): attributes %s and %s must be of abstime type",
- relname, args[0], args[1]);
+ elog(ERROR, "ttdummy (%s): attribute %s must be of integer type",
+ relname, args[i]);
}
oldon = SPI_getbinval(trigtuple, tupdesc, attnum[0], &isnull);