desc = CreateTemplateTupleDesc(tupdesc->natts);
- /* Flat-copy the attribute array */
- memcpy(TupleDescAttr(desc, 0),
- TupleDescAttr(tupdesc, 0),
- desc->natts * sizeof(FormData_pg_attribute));
+ /* Flat-copy the attribute array (unless there are no attributes) */
+ if (desc->natts > 0)
+ memcpy(TupleDescAttr(desc, 0),
+ TupleDescAttr(tupdesc, 0),
+ desc->natts * sizeof(FormData_pg_attribute));
/*
* Since we're not copying constraints and defaults, clear fields
desc = CreateTemplateTupleDesc(natts);
- /* Flat-copy the attribute array */
- memcpy(TupleDescAttr(desc, 0),
- TupleDescAttr(tupdesc, 0),
- desc->natts * sizeof(FormData_pg_attribute));
+ /* Flat-copy the attribute array (unless there are no attributes) */
+ if (desc->natts > 0)
+ memcpy(TupleDescAttr(desc, 0),
+ TupleDescAttr(tupdesc, 0),
+ desc->natts * sizeof(FormData_pg_attribute));
/*
* Since we're not copying constraints and defaults, clear fields
desc = CreateTemplateTupleDesc(tupdesc->natts);
- /* Flat-copy the attribute array */
- memcpy(TupleDescAttr(desc, 0),
- TupleDescAttr(tupdesc, 0),
- desc->natts * sizeof(FormData_pg_attribute));
+ /* Flat-copy the attribute array (unless there are no attributes) */
+ if (desc->natts > 0)
+ memcpy(TupleDescAttr(desc, 0),
+ TupleDescAttr(tupdesc, 0),
+ desc->natts * sizeof(FormData_pg_attribute));
for (i = 0; i < desc->natts; i++)
{
SV *val = HeVAL(he);
char *key = hek2cstr(he);
int attn = SPI_fnumber(td, key);
- Form_pg_attribute attr = TupleDescAttr(td, attn - 1);
+ Form_pg_attribute attr;
if (attn == SPI_ERROR_NOATTRIBUTE)
ereport(ERROR,
errmsg("cannot set system attribute \"%s\"",
key)));
+ attr = TupleDescAttr(td, attn - 1);
values[attn - 1] = plperl_sv_to_datum(val,
attr->atttypid,
attr->atttypmod,
char *key = hek2cstr(he);
SV *val = HeVAL(he);
int attn = SPI_fnumber(tupdesc, key);
- Form_pg_attribute attr = TupleDescAttr(tupdesc, attn - 1);
+ Form_pg_attribute attr;
if (attn == SPI_ERROR_NOATTRIBUTE)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot set system attribute \"%s\"",
key)));
+
+ attr = TupleDescAttr(tupdesc, attn - 1);
if (attr->attgenerated)
ereport(ERROR,
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
PLpgSQL_var *var = (PLpgSQL_var *) retvar;
Datum retval = var->value;
bool isNull = var->isnull;
- Form_pg_attribute attr = TupleDescAttr(tupdesc, 0);
+ Form_pg_attribute attr;
if (natts != 1)
ereport(ERROR,
var->datatype->typlen);
/* coerce type if needed */
+ attr = TupleDescAttr(tupdesc, 0);
retval = exec_cast_value(estate,
retval,
&isNull,
}
else
{
- Form_pg_attribute attr = TupleDescAttr(tupdesc, 0);
+ Form_pg_attribute attr;
/* Simple scalar result */
if (natts != 1)
errmsg("wrong result type supplied in RETURN NEXT")));
/* coerce type if needed */
+ attr = TupleDescAttr(tupdesc, 0);
retval = exec_cast_value(estate,
retval,
&isNull,