needComma = false;
for (i = 0; i < natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
+ if (att->attisdropped)
continue;
if (needComma)
appendStringInfoChar(&buf, ',');
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
+ quote_ident_cstr(NameStr(att->attname)));
needComma = true;
}
needComma = false;
for (i = 0; i < natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ if (TupleDescAttr(tupdesc, i)->attisdropped)
continue;
if (needComma)
for (i = 0; i < pknumatts; i++)
{
int pkattnum = pkattnums[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
if (i > 0)
appendStringInfoString(&buf, " AND ");
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
if (tgt_pkattvals[i] != NULL)
appendStringInfo(&buf, " = %s",
needComma = false;
for (i = 0; i < natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+
+ if (attr->attisdropped)
continue;
if (needComma)
appendStringInfoString(&buf, ", ");
appendStringInfo(&buf, "%s = ",
- quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
key = get_attnum_pk_pos(pkattnums, pknumatts, i);
for (i = 0; i < pknumatts; i++)
{
int pkattnum = pkattnums[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
if (i > 0)
appendStringInfoString(&buf, " AND ");
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
val = tgt_pkattvals[i];
for (i = 0; i < natts; i++)
{
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+
if (i > 0)
appendStringInfoString(&buf, ", ");
- if (tupdesc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
appendStringInfoString(&buf, "NULL");
else
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
}
appendStringInfo(&buf, " FROM %s WHERE ", relname);
for (i = 0; i < pknumatts; i++)
{
int pkattnum = pkattnums[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
if (i > 0)
appendStringInfoString(&buf, " AND ");
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
if (src_pkattvals[i] != NULL)
appendStringInfo(&buf, " = %s",
for (j = 0; j < natts; j++)
{
/* dropped columns don't count */
- if (tupdesc->attrs[j]->attisdropped)
+ if (TupleDescAttr(tupdesc, j)->attisdropped)
continue;
if (++lnum == pkattnum)
/* Retrieve FDW options for all user-defined attributes. */
for (attnum = 1; attnum <= natts; attnum++)
{
- Form_pg_attribute attr = tupleDesc->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum - 1);
List *options;
ListCell *lc;
/* Get user attributes. */
if (attnum > 0)
{
- Form_pg_attribute attr = tupleDesc->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum - 1);
char *attname = NameStr(attr->attname);
/* Skip dropped attributes (probably shouldn't see any here). */
numattrs = 0;
for (i = 0; i < tupleDesc->natts; i++)
{
- Form_pg_attribute attr = tupleDesc->attrs[i];
+ Form_pg_attribute attr = TupleDescAttr(tupleDesc, i);
if (attr->attisdropped)
continue;
for (i = 0, j = 0; i < ncolumns; ++i)
{
ColumnIOData *column_info = &my_extra->columns[i];
- Oid column_type = tupdesc->attrs[i]->atttypid;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+ Oid column_type = att->atttypid;
char *value;
/* Ignore dropped columns in datatype */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
- pairs[j].key = NameStr(tupdesc->attrs[i]->attname);
- pairs[j].keylen = hstoreCheckKeyLen(strlen(NameStr(tupdesc->attrs[i]->attname)));
+ pairs[j].key = NameStr(att->attname);
+ pairs[j].keylen = hstoreCheckKeyLen(strlen(NameStr(att->attname)));
if (!nulls || nulls[i])
{
for (i = 0; i < ncolumns; ++i)
{
ColumnIOData *column_info = &my_extra->columns[i];
- Oid column_type = tupdesc->attrs[i]->atttypid;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+ Oid column_type = att->atttypid;
char *value;
int idx;
int vallen;
/* Ignore dropped columns in datatype */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
{
nulls[i] = true;
continue;
}
idx = hstoreFindKey(hs, 0,
- NameStr(tupdesc->attrs[i]->attname),
- strlen(NameStr(tupdesc->attrs[i]->attname)));
+ NameStr(att->attname),
+ strlen(NameStr(att->attname)));
/*
* we can't just skip here if the key wasn't found since we might have
*/
values[i] = InputFunctionCall(&column_info->proc, NULL,
column_info->typioparam,
- tupdesc->attrs[i]->atttypmod);
+ att->atttypmod);
nulls[i] = true;
}
else
values[i] = InputFunctionCall(&column_info->proc, value,
column_info->typioparam,
- tupdesc->attrs[i]->atttypmod);
+ att->atttypmod);
nulls[i] = false;
}
}
bool is_null;
bytea *attr_data = NULL;
- attr = tupdesc->attrs[i];
+ attr = TupleDescAttr(tupdesc, i);
is_null = (t_infomask & HEAP_HASNULL) && att_isnull(i, t_bits);
/*
if (attr->attlen == -1)
{
- off = att_align_pointer(off, tupdesc->attrs[i]->attalign, -1,
+ off = att_align_pointer(off, attr->attalign, -1,
tupdata + off);
/*
}
else
{
- off = att_align_nominal(off, tupdesc->attrs[i]->attalign);
+ off = att_align_nominal(off, attr->attalign);
len = attr->attlen;
}
memcpy(VARDATA(attr_data), tupdata + off, len);
}
- off = att_addlength_pointer(off, tupdesc->attrs[i]->attlen,
+ off = att_addlength_pointer(off, attr->attlen,
tupdata + off);
}
lsn = PageGetLSN(page);
/* pageinspect >= 1.2 uses pg_lsn instead of text for the LSN field. */
- if (tupdesc->attrs[0]->atttypid == TEXTOID)
+ if (TupleDescAttr(tupdesc, 0)->atttypid == TEXTOID)
{
char lsnchar[64];
first = true;
for (i = 1; i <= tupdesc->natts; i++)
{
- Form_pg_attribute attr = tupdesc->attrs[i - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i - 1);
/* Ignore dropped attributes. */
if (attr->attisdropped)
for (i = 0; i < tupdesc->natts; i++)
{
/* Ignore dropped columns. */
- if (tupdesc->attrs[i]->attisdropped)
+ if (TupleDescAttr(tupdesc, i)->attisdropped)
continue;
if (!first)
first = false;
/* Use attribute name or column_name option. */
- colname = NameStr(tupdesc->attrs[i]->attname);
+ colname = NameStr(TupleDescAttr(tupdesc, i)->attname);
options = GetForeignColumnOptions(relid, i + 1);
foreach(lc, options)
for (attnum = 1; attnum <= tupdesc->natts; attnum++)
{
- Form_pg_attribute attr = tupdesc->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
if (!attr->attisdropped)
targetAttrs = lappend_int(targetAttrs, attnum);
Oid typefnoid;
bool isvarlena;
ListCell *lc;
+ TupleDesc tupdesc = RelationGetDescr(rel);
/*
* Do nothing in EXPLAIN (no ANALYZE) case. resultRelInfo->ri_FdwState
/* Prepare for input conversion of RETURNING results. */
if (fmstate->has_returning)
- fmstate->attinmeta = TupleDescGetAttInMetadata(RelationGetDescr(rel));
+ fmstate->attinmeta = TupleDescGetAttInMetadata(tupdesc);
/* Prepare for output conversion of parameters used in prepared stmt. */
n_params = list_length(fmstate->target_attrs) + 1;
foreach(lc, fmstate->target_attrs)
{
int attnum = lfirst_int(lc);
- Form_pg_attribute attr = RelationGetDescr(rel)->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
Assert(!attr->attisdropped);
{
/* error occurred in a scan against a foreign table */
TupleDesc tupdesc = RelationGetDescr(errpos->rel);
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, errpos->cur_attno - 1);
if (errpos->cur_attno > 0 && errpos->cur_attno <= tupdesc->natts)
- attname = NameStr(tupdesc->attrs[errpos->cur_attno - 1]->attname);
+ attname = NameStr(attr->attname);
else if (errpos->cur_attno == SelfItemPointerAttributeNumber)
attname = "ctid";
else if (errpos->cur_attno == ObjectIdAttributeNumber)
for (i = 1; i <= natts; i++)
{
ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
- if (!(tupdesc->attrs[i - 1]->attisdropped)) /* skip dropped columns */
+ if (!(TupleDescAttr(tupdesc, i - 1)->attisdropped)) /* skip dropped columns */
{
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), "%c$%d", separ, i);
separ = ',';
* Check expected (query runtime) tupdesc suitable for Connectby
*/
static void
-validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial)
+validateConnectbyTupleDesc(TupleDesc td, bool show_branch, bool show_serial)
{
int serial_column = 0;
/* are there the correct number of columns */
if (show_branch)
{
- if (tupdesc->natts != (CONNECTBY_NCOLS + serial_column))
+ if (td->natts != (CONNECTBY_NCOLS + serial_column))
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
}
else
{
- if (tupdesc->natts != CONNECTBY_NCOLS_NOBRANCH + serial_column)
+ if (td->natts != CONNECTBY_NCOLS_NOBRANCH + serial_column)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
}
/* check that the types of the first two columns match */
- if (tupdesc->attrs[0]->atttypid != tupdesc->attrs[1]->atttypid)
+ if (TupleDescAttr(td, 0)->atttypid != TupleDescAttr(td, 1)->atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
errdetail("First two columns must be the same type.")));
/* check that the type of the third column is INT4 */
- if (tupdesc->attrs[2]->atttypid != INT4OID)
+ if (TupleDescAttr(td, 2)->atttypid != INT4OID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
format_type_be(INT4OID))));
/* check that the type of the fourth column is TEXT if applicable */
- if (show_branch && tupdesc->attrs[3]->atttypid != TEXTOID)
+ if (show_branch && TupleDescAttr(td, 3)->atttypid != TEXTOID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
format_type_be(TEXTOID))));
/* check that the type of the fifth column is INT4 */
- if (show_branch && show_serial && tupdesc->attrs[4]->atttypid != INT4OID)
+ if (show_branch && show_serial &&
+ TupleDescAttr(td, 4)->atttypid != INT4OID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("query-specified return tuple not valid for Connectby: "
format_type_be(INT4OID))));
/* check that the type of the fifth column is INT4 */
- if (!show_branch && show_serial && tupdesc->attrs[3]->atttypid != INT4OID)
+ if (!show_branch && show_serial &&
+ TupleDescAttr(td, 3)->atttypid != INT4OID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("query-specified return tuple not valid for Connectby: "
* These columns must match the result type indicated by the calling
* query.
*/
- ret_atttypid = ret_tupdesc->attrs[0]->atttypid;
- sql_atttypid = sql_tupdesc->attrs[0]->atttypid;
- ret_atttypmod = ret_tupdesc->attrs[0]->atttypmod;
- sql_atttypmod = sql_tupdesc->attrs[0]->atttypmod;
+ ret_atttypid = TupleDescAttr(ret_tupdesc, 0)->atttypid;
+ sql_atttypid = TupleDescAttr(sql_tupdesc, 0)->atttypid;
+ ret_atttypmod = TupleDescAttr(ret_tupdesc, 0)->atttypmod;
+ sql_atttypmod = TupleDescAttr(sql_tupdesc, 0)->atttypmod;
if (ret_atttypid != sql_atttypid ||
(ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod))
ereport(ERROR,
format_type_with_typemod(ret_atttypid, ret_atttypmod),
format_type_with_typemod(sql_atttypid, sql_atttypmod))));
- ret_atttypid = ret_tupdesc->attrs[1]->atttypid;
- sql_atttypid = sql_tupdesc->attrs[1]->atttypid;
- ret_atttypmod = ret_tupdesc->attrs[1]->atttypmod;
- sql_atttypmod = sql_tupdesc->attrs[1]->atttypmod;
+ ret_atttypid = TupleDescAttr(ret_tupdesc, 1)->atttypid;
+ sql_atttypid = TupleDescAttr(sql_tupdesc, 1)->atttypid;
+ ret_atttypmod = TupleDescAttr(ret_tupdesc, 1)->atttypmod;
+ sql_atttypmod = TupleDescAttr(sql_tupdesc, 1)->atttypmod;
if (ret_atttypid != sql_atttypid ||
(ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod))
ereport(ERROR,
return false;
/* check the rowid types match */
- ret_atttypid = ret_tupdesc->attrs[0]->atttypid;
- sql_atttypid = sql_tupdesc->attrs[0]->atttypid;
+ ret_atttypid = TupleDescAttr(ret_tupdesc, 0)->atttypid;
+ sql_atttypid = TupleDescAttr(sql_tupdesc, 0)->atttypid;
if (ret_atttypid != sql_atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
* attribute [2] of the sql tuple should match attributes [1] to [natts]
* of the return tuple
*/
- sql_attr = sql_tupdesc->attrs[2];
+ sql_attr = TupleDescAttr(sql_tupdesc, 2);
for (i = 1; i < ret_tupdesc->natts; i++)
{
- ret_attr = ret_tupdesc->attrs[i];
+ ret_attr = TupleDescAttr(ret_tupdesc, i);
if (ret_attr->atttypid != sql_attr->atttypid)
return false;
for (i = 0; i < numatts; i++)
{
int colno = index->indkey.values[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, colno - 1);
appendStringInfoCharMacro(payload, ',');
- strcpy_quoted(payload, NameStr((tupdesc->attrs[colno - 1])->attname), '"');
+ strcpy_quoted(payload, NameStr(attr->attname), '"');
appendStringInfoCharMacro(payload, '=');
strcpy_quoted(payload, SPI_getvalue(trigtuple, tupdesc, colno), '\'');
}
Datum origval; /* possibly toasted Datum */
bool isnull; /* column is null? */
- attr = tupdesc->attrs[natt];
+ attr = TupleDescAttr(tupdesc, natt);
/*
* don't print dropped columns, we can't be sure everything is
*/
Assert((key->sk_flags & SK_ISNULL) ||
(key->sk_collation ==
- bdesc->bd_tupdesc->attrs[keyattno - 1]->attcollation));
+ TupleDescAttr(bdesc->bd_tupdesc,
+ keyattno - 1)->attcollation));
/* First time this column? look up consistent function */
if (consistentFn[keyattno - 1].fn_oid == InvalidOid)
{
FmgrInfo *addValue;
BrinValues *col;
+ Form_pg_attribute attr = TupleDescAttr(state->bs_bdesc->bd_tupdesc, i);
col = &state->bs_dtuple->bt_columns[i];
addValue = index_getprocinfo(index, i + 1,
* Update dtuple state, if and as necessary.
*/
FunctionCall4Coll(addValue,
- state->bs_bdesc->bd_tupdesc->attrs[i]->attcollation,
+ attr->attcollation,
PointerGetDatum(state->bs_bdesc),
PointerGetDatum(col),
values[i], isnull[i]);
for (keyno = 0; keyno < tupdesc->natts; keyno++)
{
FmgrInfo *opcInfoFn;
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, keyno);
opcInfoFn = index_getprocinfo(rel, keyno + 1, BRIN_PROCNUM_OPCINFO);
opcinfo[keyno] = (BrinOpcInfo *)
- DatumGetPointer(FunctionCall1(opcInfoFn,
- tupdesc->attrs[keyno]->atttypid));
+ DatumGetPointer(FunctionCall1(opcInfoFn, attr->atttypid));
totalstored += opcinfo[keyno]->oi_nstored;
}
}
attno = column->bv_attno;
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
/*
* If the recorded value is null, copy the new value (which we know to be
PG_RETURN_VOID();
attno = col_a->bv_attno;
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
/*
* Adjust "allnulls". If A doesn't have values, just copy the values from
bool isNull;
opfamily = bdesc->bd_index->rd_opfamily[attno - 1];
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
tuple = SearchSysCache4(AMOPSTRATEGY, ObjectIdGetDatum(opfamily),
ObjectIdGetDatum(attr->atttypid),
ObjectIdGetDatum(subtype),
}
attno = column->bv_attno;
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
/*
* If the recorded value is null, store the new value (which we know to be
PG_RETURN_VOID();
attno = col_a->bv_attno;
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
/*
* Adjust "allnulls". If A doesn't have values, just copy the values from
bool isNull;
opfamily = bdesc->bd_index->rd_opfamily[attno - 1];
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
tuple = SearchSysCache4(AMOPSTRATEGY, ObjectIdGetDatum(opfamily),
ObjectIdGetDatum(attr->atttypid),
ObjectIdGetDatum(subtype),
datumno < brdesc->bd_info[attnum]->oi_nstored;
datumno++)
{
- Form_pg_attribute thisatt = diskdsc->attrs[stored];
+ Form_pg_attribute thisatt = TupleDescAttr(diskdsc, stored);
if (thisatt->attlen == -1)
{
Size data_length = 0;
int i;
int numberOfAttributes = tupleDesc->natts;
- Form_pg_attribute *att = tupleDesc->attrs;
for (i = 0; i < numberOfAttributes; i++)
{
continue;
val = values[i];
- atti = att[i];
+ atti = TupleDescAttr(tupleDesc, i);
if (ATT_IS_PACKABLE(atti) &&
VARATT_CAN_MAKE_SHORT(DatumGetPointer(val)))
int bitmask;
int i;
int numberOfAttributes = tupleDesc->natts;
- Form_pg_attribute *att = tupleDesc->attrs;
#ifdef USE_ASSERT_CHECKING
char *start = data;
for (i = 0; i < numberOfAttributes; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
Size data_length;
if (bit != NULL)
* an offset. This is a bit of a hack.
*/
- if (att[i]->attbyval)
+ if (att->attbyval)
{
/* pass-by-value */
- data = (char *) att_align_nominal(data, att[i]->attalign);
- store_att_byval(data, values[i], att[i]->attlen);
- data_length = att[i]->attlen;
+ data = (char *) att_align_nominal(data, att->attalign);
+ store_att_byval(data, values[i], att->attlen);
+ data_length = att->attlen;
}
- else if (att[i]->attlen == -1)
+ else if (att->attlen == -1)
{
/* varlena */
Pointer val = DatumGetPointer(values[i]);
ExpandedObjectHeader *eoh = DatumGetEOHP(values[i]);
data = (char *) att_align_nominal(data,
- att[i]->attalign);
+ att->attalign);
data_length = EOH_get_flat_size(eoh);
EOH_flatten_into(eoh, data, data_length);
}
data_length = VARSIZE_SHORT(val);
memcpy(data, val, data_length);
}
- else if (VARLENA_ATT_IS_PACKABLE(att[i]) &&
+ else if (VARLENA_ATT_IS_PACKABLE(att) &&
VARATT_CAN_MAKE_SHORT(val))
{
/* convert to short varlena -- no alignment */
{
/* full 4-byte header varlena */
data = (char *) att_align_nominal(data,
- att[i]->attalign);
+ att->attalign);
data_length = VARSIZE(val);
memcpy(data, val, data_length);
}
}
- else if (att[i]->attlen == -2)
+ else if (att->attlen == -2)
{
/* cstring ... never needs alignment */
*infomask |= HEAP_HASVARWIDTH;
- Assert(att[i]->attalign == 'c');
+ Assert(att->attalign == 'c');
data_length = strlen(DatumGetCString(values[i])) + 1;
memcpy(data, DatumGetPointer(values[i]), data_length);
}
else
{
/* fixed-length pass-by-reference */
- data = (char *) att_align_nominal(data, att[i]->attalign);
- Assert(att[i]->attlen > 0);
- data_length = att[i]->attlen;
+ data = (char *) att_align_nominal(data, att->attalign);
+ Assert(att->attlen > 0);
+ data_length = att->attlen;
memcpy(data, DatumGetPointer(values[i]), data_length);
}
TupleDesc tupleDesc)
{
HeapTupleHeader tup = tuple->t_data;
- Form_pg_attribute *att = tupleDesc->attrs;
char *tp; /* ptr to data part of tuple */
bits8 *bp = tup->t_bits; /* ptr to null bitmap in tuple */
bool slow = false; /* do we have to walk attrs? */
if (!slow)
{
+ Form_pg_attribute att;
+
/*
* If we get here, there are no nulls up to and including the target
* attribute. If we have a cached offset, we can use it.
*/
- if (att[attnum]->attcacheoff >= 0)
- {
- return fetchatt(att[attnum],
- tp + att[attnum]->attcacheoff);
- }
+ att = TupleDescAttr(tupleDesc, attnum);
+ if (att->attcacheoff >= 0)
+ return fetchatt(att, tp + att->attcacheoff);
/*
* Otherwise, check for non-fixed-length attrs up to and including
for (j = 0; j <= attnum; j++)
{
- if (att[j]->attlen <= 0)
+ if (TupleDescAttr(tupleDesc, j)->attlen <= 0)
{
slow = true;
break;
* fixed-width columns, in hope of avoiding future visits to this
* routine.
*/
- att[0]->attcacheoff = 0;
+ TupleDescAttr(tupleDesc, 0)->attcacheoff = 0;
/* we might have set some offsets in the slow path previously */
- while (j < natts && att[j]->attcacheoff > 0)
+ while (j < natts && TupleDescAttr(tupleDesc, j)->attcacheoff > 0)
j++;
- off = att[j - 1]->attcacheoff + att[j - 1]->attlen;
+ off = TupleDescAttr(tupleDesc, j - 1)->attcacheoff +
+ TupleDescAttr(tupleDesc, j - 1)->attlen;
for (; j < natts; j++)
{
- if (att[j]->attlen <= 0)
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, j);
+
+ if (att->attlen <= 0)
break;
- off = att_align_nominal(off, att[j]->attalign);
+ off = att_align_nominal(off, att->attalign);
- att[j]->attcacheoff = off;
+ att->attcacheoff = off;
- off += att[j]->attlen;
+ off += att->attlen;
}
Assert(j > attnum);
- off = att[attnum]->attcacheoff;
+ off = TupleDescAttr(tupleDesc, attnum)->attcacheoff;
}
else
{
off = 0;
for (i = 0;; i++) /* loop exit is at "break" */
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
+
if (HeapTupleHasNulls(tuple) && att_isnull(i, bp))
{
usecache = false;
}
/* If we know the next offset, we can skip the rest */
- if (usecache && att[i]->attcacheoff >= 0)
- off = att[i]->attcacheoff;
- else if (att[i]->attlen == -1)
+ if (usecache && att->attcacheoff >= 0)
+ off = att->attcacheoff;
+ else if (att->attlen == -1)
{
/*
* We can only cache the offset for a varlena attribute if the
* either an aligned or unaligned value.
*/
if (usecache &&
- off == att_align_nominal(off, att[i]->attalign))
- att[i]->attcacheoff = off;
+ off == att_align_nominal(off, att->attalign))
+ att->attcacheoff = off;
else
{
- off = att_align_pointer(off, att[i]->attalign, -1,
+ off = att_align_pointer(off, att->attalign, -1,
tp + off);
usecache = false;
}
else
{
/* not varlena, so safe to use att_align_nominal */
- off = att_align_nominal(off, att[i]->attalign);
+ off = att_align_nominal(off, att->attalign);
if (usecache)
- att[i]->attcacheoff = off;
+ att->attcacheoff = off;
}
if (i == attnum)
break;
- off = att_addlength_pointer(off, att[i]->attlen, tp + off);
+ off = att_addlength_pointer(off, att->attlen, tp + off);
- if (usecache && att[i]->attlen <= 0)
+ if (usecache && att->attlen <= 0)
usecache = false;
}
}
- return fetchatt(att[attnum], tp + off);
+ return fetchatt(TupleDescAttr(tupleDesc, attnum), tp + off);
}
/* ----------------
{
HeapTupleHeader tup = tuple->t_data;
bool hasnulls = HeapTupleHasNulls(tuple);
- Form_pg_attribute *att = tupleDesc->attrs;
int tdesc_natts = tupleDesc->natts;
int natts; /* number of atts to extract */
int attnum;
for (attnum = 0; attnum < natts; attnum++)
{
- Form_pg_attribute thisatt = att[attnum];
+ Form_pg_attribute thisatt = TupleDescAttr(tupleDesc, attnum);
if (hasnulls && att_isnull(attnum, bp))
{
bool *isnull = slot->tts_isnull;
HeapTupleHeader tup = tuple->t_data;
bool hasnulls = HeapTupleHasNulls(tuple);
- Form_pg_attribute *att = tupleDesc->attrs;
int attnum;
char *tp; /* ptr to tuple data */
long off; /* offset in tuple data */
for (; attnum < natts; attnum++)
{
- Form_pg_attribute thisatt = att[attnum];
+ Form_pg_attribute thisatt = TupleDescAttr(tupleDesc, attnum);
if (hasnulls && att_isnull(attnum, bp))
{
* This case should not happen in normal use, but it could happen if we
* are executing a plan cached before the column was dropped.
*/
- if (tupleDesc->attrs[attnum - 1]->attisdropped)
+ if (TupleDescAttr(tupleDesc, attnum - 1)->attisdropped)
{
*isnull = true;
return (Datum) 0;
#ifdef TOAST_INDEX_HACK
for (i = 0; i < numberOfAttributes; i++)
{
- Form_pg_attribute att = tupleDescriptor->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(tupleDescriptor, i);
untoasted_values[i] = values[i];
untoasted_free[i] = false;
int attnum,
TupleDesc tupleDesc)
{
- Form_pg_attribute *att = tupleDesc->attrs;
char *tp; /* ptr to data part of tuple */
bits8 *bp = NULL; /* ptr to null bitmap in tuple */
bool slow = false; /* do we have to walk attrs? */
if (!slow)
{
+ Form_pg_attribute att;
+
/*
* If we get here, there are no nulls up to and including the target
* attribute. If we have a cached offset, we can use it.
*/
- if (att[attnum]->attcacheoff >= 0)
- {
- return fetchatt(att[attnum],
- tp + att[attnum]->attcacheoff);
- }
+ att = TupleDescAttr(tupleDesc, attnum);
+ if (att->attcacheoff >= 0)
+ return fetchatt(att, tp + att->attcacheoff);
/*
* Otherwise, check for non-fixed-length attrs up to and including
for (j = 0; j <= attnum; j++)
{
- if (att[j]->attlen <= 0)
+ if (TupleDescAttr(tupleDesc, j)->attlen <= 0)
{
slow = true;
break;
* fixed-width columns, in hope of avoiding future visits to this
* routine.
*/
- att[0]->attcacheoff = 0;
+ TupleDescAttr(tupleDesc, 0)->attcacheoff = 0;
/* we might have set some offsets in the slow path previously */
- while (j < natts && att[j]->attcacheoff > 0)
+ while (j < natts && TupleDescAttr(tupleDesc, j)->attcacheoff > 0)
j++;
- off = att[j - 1]->attcacheoff + att[j - 1]->attlen;
+ off = TupleDescAttr(tupleDesc, j - 1)->attcacheoff +
+ TupleDescAttr(tupleDesc, j - 1)->attlen;
for (; j < natts; j++)
{
- if (att[j]->attlen <= 0)
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, j);
+
+ if (att->attlen <= 0)
break;
- off = att_align_nominal(off, att[j]->attalign);
+ off = att_align_nominal(off, att->attalign);
- att[j]->attcacheoff = off;
+ att->attcacheoff = off;
- off += att[j]->attlen;
+ off += att->attlen;
}
Assert(j > attnum);
- off = att[attnum]->attcacheoff;
+ off = TupleDescAttr(tupleDesc, attnum)->attcacheoff;
}
else
{
off = 0;
for (i = 0;; i++) /* loop exit is at "break" */
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
+
if (IndexTupleHasNulls(tup) && att_isnull(i, bp))
{
usecache = false;
}
/* If we know the next offset, we can skip the rest */
- if (usecache && att[i]->attcacheoff >= 0)
- off = att[i]->attcacheoff;
- else if (att[i]->attlen == -1)
+ if (usecache && att->attcacheoff >= 0)
+ off = att->attcacheoff;
+ else if (att->attlen == -1)
{
/*
* We can only cache the offset for a varlena attribute if the
* either an aligned or unaligned value.
*/
if (usecache &&
- off == att_align_nominal(off, att[i]->attalign))
- att[i]->attcacheoff = off;
+ off == att_align_nominal(off, att->attalign))
+ att->attcacheoff = off;
else
{
- off = att_align_pointer(off, att[i]->attalign, -1,
+ off = att_align_pointer(off, att->attalign, -1,
tp + off);
usecache = false;
}
else
{
/* not varlena, so safe to use att_align_nominal */
- off = att_align_nominal(off, att[i]->attalign);
+ off = att_align_nominal(off, att->attalign);
if (usecache)
- att[i]->attcacheoff = off;
+ att->attcacheoff = off;
}
if (i == attnum)
break;
- off = att_addlength_pointer(off, att[i]->attlen, tp + off);
+ off = att_addlength_pointer(off, att->attlen, tp + off);
- if (usecache && att[i]->attlen <= 0)
+ if (usecache && att->attlen <= 0)
usecache = false;
}
}
- return fetchatt(att[attnum], tp + off);
+ return fetchatt(TupleDescAttr(tupleDesc, attnum), tp + off);
}
/*
for (i = 0; i < tupdesc->natts; ++i)
{
- Form_pg_attribute attr = tupdesc->attrs[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
pq_sendstring(&buf, NameStr(attr->attname));
pq_sendint(&buf, 0, 4); /* table oid */
for (i = 0; i < tupdesc->natts; ++i)
{
- Form_pg_attribute attr = tupdesc->attrs[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
Datum value;
if (slot->tts_isnull[i])
void
SendRowDescriptionMessage(TupleDesc typeinfo, List *targetlist, int16 *formats)
{
- Form_pg_attribute *attrs = typeinfo->attrs;
int natts = typeinfo->natts;
int proto = PG_PROTOCOL_MAJOR(FrontendProtocol);
int i;
for (i = 0; i < natts; ++i)
{
- Oid atttypid = attrs[i]->atttypid;
- int32 atttypmod = attrs[i]->atttypmod;
+ Form_pg_attribute att = TupleDescAttr(typeinfo, i);
+ Oid atttypid = att->atttypid;
+ int32 atttypmod = att->atttypmod;
- pq_sendstring(&buf, NameStr(attrs[i]->attname));
+ pq_sendstring(&buf, NameStr(att->attname));
/* column ID info appears in protocol 3.0 and up */
if (proto >= 3)
{
/* If column is a domain, send the base type and typmod instead */
atttypid = getBaseTypeAndTypmod(atttypid, &atttypmod);
pq_sendint(&buf, (int) atttypid, sizeof(atttypid));
- pq_sendint(&buf, attrs[i]->attlen, sizeof(attrs[i]->attlen));
+ pq_sendint(&buf, att->attlen, sizeof(att->attlen));
pq_sendint(&buf, atttypmod, sizeof(atttypmod));
/* format info appears in protocol 3.0 and up */
if (proto >= 3)
{
PrinttupAttrInfo *thisState = myState->myinfo + i;
int16 format = (formats ? formats[i] : 0);
+ Form_pg_attribute attr = TupleDescAttr(typeinfo, i);
thisState->format = format;
if (format == 0)
{
- getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
+ getTypeOutputInfo(attr->atttypid,
&thisState->typoutput,
&thisState->typisvarlena);
fmgr_info(thisState->typoutput, &thisState->finfo);
}
else if (format == 1)
{
- getTypeBinaryOutputInfo(typeinfo->attrs[i]->atttypid,
+ getTypeBinaryOutputInfo(attr->atttypid,
&thisState->typsend,
&thisState->typisvarlena);
fmgr_info(thisState->typsend, &thisState->finfo);
debugStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
{
int natts = typeinfo->natts;
- Form_pg_attribute *attinfo = typeinfo->attrs;
int i;
/*
* show the return type of the tuples
*/
for (i = 0; i < natts; ++i)
- printatt((unsigned) i + 1, attinfo[i], NULL);
+ printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), NULL);
printf("\t----\n");
}
attr = slot_getattr(slot, i + 1, &isnull);
if (isnull)
continue;
- getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
+ getTypeOutputInfo(TupleDescAttr(typeinfo, i)->atttypid,
&typoutput, &typisvarlena);
value = OidOutputFunctionCall(typoutput, attr);
- printatt((unsigned) i + 1, typeinfo->attrs[i], value);
+ printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), value);
}
printf("\t----\n");
same = true;
for (i = 0; i < n; i++)
{
- Form_pg_attribute att = outdesc->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(outdesc, i);
Oid atttypid;
int32 atttypmod;
atttypmod = att->atttypmod;
for (; j < indesc->natts; j++)
{
- att = indesc->attrs[j];
+ att = TupleDescAttr(indesc, j);
if (att->attisdropped)
continue;
nincols++;
/* Check for unused input columns */
for (; j < indesc->natts; j++)
{
- if (indesc->attrs[j]->attisdropped)
+ if (TupleDescAttr(indesc, j)->attisdropped)
continue;
nincols++;
same = false; /* we'll complain below */
{
for (i = 0; i < n; i++)
{
+ Form_pg_attribute inatt;
+ Form_pg_attribute outatt;
+
if (attrMap[i] == (i + 1))
continue;
* also dropped, we needn't convert. However, attlen and attalign
* must agree.
*/
+ inatt = TupleDescAttr(indesc, i);
+ outatt = TupleDescAttr(outdesc, i);
if (attrMap[i] == 0 &&
- indesc->attrs[i]->attisdropped &&
- indesc->attrs[i]->attlen == outdesc->attrs[i]->attlen &&
- indesc->attrs[i]->attalign == outdesc->attrs[i]->attalign)
+ inatt->attisdropped &&
+ inatt->attlen == outatt->attlen &&
+ inatt->attalign == outatt->attalign)
continue;
same = false;
same = true;
for (i = 0; i < n; i++)
{
+ Form_pg_attribute inatt;
+ Form_pg_attribute outatt;
+
if (attrMap[i] == (i + 1))
continue;
* also dropped, we needn't convert. However, attlen and attalign
* must agree.
*/
+ inatt = TupleDescAttr(indesc, i);
+ outatt = TupleDescAttr(outdesc, i);
if (attrMap[i] == 0 &&
- indesc->attrs[i]->attisdropped &&
- indesc->attrs[i]->attlen == outdesc->attrs[i]->attlen &&
- indesc->attrs[i]->attalign == outdesc->attrs[i]->attalign)
+ inatt->attisdropped &&
+ inatt->attlen == outatt->attlen &&
+ inatt->attalign == outatt->attalign)
continue;
same = false;
attrMap = (AttrNumber *) palloc0(n * sizeof(AttrNumber));
for (i = 0; i < n; i++)
{
- Form_pg_attribute att = outdesc->attrs[i];
+ Form_pg_attribute outatt = TupleDescAttr(outdesc, i);
char *attname;
Oid atttypid;
int32 atttypmod;
int j;
- if (att->attisdropped)
+ if (outatt->attisdropped)
continue; /* attrMap[i] is already 0 */
- attname = NameStr(att->attname);
- atttypid = att->atttypid;
- atttypmod = att->atttypmod;
+ attname = NameStr(outatt->attname);
+ atttypid = outatt->atttypid;
+ atttypmod = outatt->atttypmod;
for (j = 0; j < indesc->natts; j++)
{
- att = indesc->attrs[j];
- if (att->attisdropped)
+ Form_pg_attribute inatt = TupleDescAttr(indesc, j);
+
+ if (inatt->attisdropped)
continue;
- if (strcmp(attname, NameStr(att->attname)) == 0)
+ if (strcmp(attname, NameStr(inatt->attname)) == 0)
{
/* Found it, check type */
- if (atttypid != att->atttypid || atttypmod != att->atttypmod)
+ if (atttypid != inatt->atttypid || atttypmod != inatt->atttypmod)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg_internal("%s", _(msg)),
for (i = 0; i < desc->natts; i++)
{
- memcpy(desc->attrs[i], tupdesc->attrs[i], ATTRIBUTE_FIXED_PART_SIZE);
+ memcpy(TupleDescAttr(desc, i),
+ TupleDescAttr(tupdesc, i),
+ ATTRIBUTE_FIXED_PART_SIZE);
}
if (constr)
TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno,
TupleDesc src, AttrNumber srcAttno)
{
+ Form_pg_attribute dstAtt = TupleDescAttr(dst, dstAttno - 1);
+ Form_pg_attribute srcAtt = TupleDescAttr(src, srcAttno - 1);
+
/*
* sanity checks
*/
AssertArg(dstAttno >= 1);
AssertArg(dstAttno <= dst->natts);
- memcpy(dst->attrs[dstAttno - 1], src->attrs[srcAttno - 1],
- ATTRIBUTE_FIXED_PART_SIZE);
+ memcpy(dstAtt, srcAtt, ATTRIBUTE_FIXED_PART_SIZE);
/*
* Aside from updating the attno, we'd better reset attcacheoff.
* by other uses of this function or TupleDescInitEntry. So we cheat a
* bit to avoid a useless O(N^2) penalty.
*/
- dst->attrs[dstAttno - 1]->attnum = dstAttno;
- dst->attrs[dstAttno - 1]->attcacheoff = -1;
+ dstAtt->attnum = dstAttno;
+ dstAtt->attcacheoff = -1;
/* since we're not copying constraints or defaults, clear these */
- dst->attrs[dstAttno - 1]->attnotnull = false;
- dst->attrs[dstAttno - 1]->atthasdef = false;
- dst->attrs[dstAttno - 1]->attidentity = '\0';
+ dstAtt->attnotnull = false;
+ dstAtt->atthasdef = false;
+ dstAtt->attidentity = '\0';
}
/*
for (i = 0; i < tupdesc1->natts; i++)
{
- Form_pg_attribute attr1 = tupdesc1->attrs[i];
- Form_pg_attribute attr2 = tupdesc2->attrs[i];
+ Form_pg_attribute attr1 = TupleDescAttr(tupdesc1, i);
+ Form_pg_attribute attr2 = TupleDescAttr(tupdesc2, i);
/*
* We do not need to check every single field here: we can disregard
/*
* initialize the attribute fields
*/
- att = desc->attrs[attributeNumber - 1];
+ att = TupleDescAttr(desc, attributeNumber - 1);
att->attrelid = 0; /* dummy value */
AssertArg(attributeNumber <= desc->natts);
/* initialize the attribute fields */
- att = desc->attrs[attributeNumber - 1];
+ att = TupleDescAttr(desc, attributeNumber - 1);
att->attrelid = 0; /* dummy value */
/* unlike TupleDescInitEntry, we require an attribute name */
AssertArg(attributeNumber >= 1);
AssertArg(attributeNumber <= desc->natts);
- desc->attrs[attributeNumber - 1]->attcollation = collationid;
+ TupleDescAttr(desc, attributeNumber - 1)->attcollation = collationid;
}
{
ColumnDef *entry = lfirst(l);
AclResult aclresult;
+ Form_pg_attribute att;
/*
* for each entry in the list, get the name and type information from
TupleDescInitEntry(desc, attnum, attname,
atttypid, atttypmod, attdim);
+ att = TupleDescAttr(desc, attnum - 1);
/* Override TupleDescInitEntry's settings as requested */
TupleDescInitEntryCollation(desc, attnum, attcollation);
if (entry->storage)
- desc->attrs[attnum - 1]->attstorage = entry->storage;
+ att->attstorage = entry->storage;
/* Fill in additional stuff not handled by TupleDescInitEntry */
- desc->attrs[attnum - 1]->attnotnull = entry->is_not_null;
+ att->attnotnull = entry->is_not_null;
has_not_null |= entry->is_not_null;
- desc->attrs[attnum - 1]->attislocal = entry->is_local;
- desc->attrs[attnum - 1]->attinhcount = entry->inhcount;
+ att->attislocal = entry->is_local;
+ att->attinhcount = entry->inhcount;
}
if (has_not_null)
static Datum
getDatumCopy(BuildAccumulator *accum, OffsetNumber attnum, Datum value)
{
- Form_pg_attribute att = accum->ginstate->origTupdesc->attrs[attnum - 1];
+ Form_pg_attribute att;
Datum res;
+ att = TupleDescAttr(accum->ginstate->origTupdesc, attnum - 1);
if (att->attbyval)
res = value;
else
/* Locate tupdesc entry for key column (for attbyval/attlen data) */
attnum = scanEntry->attnum;
- attr = btree->ginstate->origTupdesc->attrs[attnum - 1];
+ attr = TupleDescAttr(btree->ginstate->origTupdesc, attnum - 1);
for (;;)
{
for (i = 0; i < origTupdesc->natts; i++)
{
+ Form_pg_attribute attr = TupleDescAttr(origTupdesc, i);
+
if (state->oneCol)
state->tupdesc[i] = state->origTupdesc;
else
TupleDescInitEntry(state->tupdesc[i], (AttrNumber) 1, NULL,
INT2OID, -1, 0);
TupleDescInitEntry(state->tupdesc[i], (AttrNumber) 2, NULL,
- origTupdesc->attrs[i]->atttypid,
- origTupdesc->attrs[i]->atttypmod,
- origTupdesc->attrs[i]->attndims);
+ attr->atttypid,
+ attr->atttypmod,
+ attr->attndims);
TupleDescInitEntryCollation(state->tupdesc[i], (AttrNumber) 2,
- origTupdesc->attrs[i]->attcollation);
+ attr->attcollation);
}
/*
{
TypeCacheEntry *typentry;
- typentry = lookup_type_cache(origTupdesc->attrs[i]->atttypid,
+ typentry = lookup_type_cache(attr->atttypid,
TYPECACHE_CMP_PROC_FINFO);
if (!OidIsValid(typentry->cmp_proc_finfo.fn_oid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("could not identify a comparison function for type %s",
- format_type_be(origTupdesc->attrs[i]->atttypid))));
+ format_type_be(attr->atttypid))));
fmgr_info_copy(&(state->compareFn[i]),
&(typentry->cmp_proc_finfo),
CurrentMemoryContext);
itupMinSize = (Size) MAXALIGN(sizeof(IndexTupleData));
for (i = 0; i < index->rd_att->natts; i++)
{
- if (index->rd_att->attrs[i]->attlen < 0)
+ if (TupleDescAttr(index->rd_att, i)->attlen < 0)
itupMinSize += VARHDRSZ;
else
- itupMinSize += index->rd_att->attrs[i]->attlen;
+ itupMinSize += TupleDescAttr(index->rd_att, i)->attlen;
}
/* Calculate average and maximal number of index tuples which fit to page */
(*(isnull) = false),
HeapTupleNoNulls(tup) ?
(
- (tupleDesc)->attrs[(attnum) - 1]->attcacheoff >= 0 ?
+ TupleDescAttr((tupleDesc), (attnum) - 1)->attcacheoff >= 0 ?
(
- fetchatt((tupleDesc)->attrs[(attnum) - 1],
+ fetchatt(TupleDescAttr((tupleDesc), (attnum) - 1),
(char *) (tup)->t_data + (tup)->t_data->t_hoff +
- (tupleDesc)->attrs[(attnum) - 1]->attcacheoff)
+ TupleDescAttr((tupleDesc), (attnum) - 1)->attcacheoff)
)
:
nocachegetattr((tup), (attnum), (tupleDesc))
else
{
Assert(attrnum <= tupdesc->natts);
- att = tupdesc->attrs[attrnum - 1];
+ att = TupleDescAttr(tupdesc, attrnum - 1);
return datumIsEqual(value1, value2, att->attbyval, att->attlen);
}
}
toast_delete(Relation rel, HeapTuple oldtup, bool is_speculative)
{
TupleDesc tupleDesc;
- Form_pg_attribute *att;
int numAttrs;
int i;
Datum toast_values[MaxHeapAttributeNumber];
* least one varlena column, by the way.)
*/
tupleDesc = rel->rd_att;
- att = tupleDesc->attrs;
numAttrs = tupleDesc->natts;
Assert(numAttrs <= MaxHeapAttributeNumber);
*/
for (i = 0; i < numAttrs; i++)
{
- if (att[i]->attlen == -1)
+ if (TupleDescAttr(tupleDesc, i)->attlen == -1)
{
Datum value = toast_values[i];
{
HeapTuple result_tuple;
TupleDesc tupleDesc;
- Form_pg_attribute *att;
int numAttrs;
int i;
* Get the tuple descriptor and break down the tuple(s) into fields.
*/
tupleDesc = rel->rd_att;
- att = tupleDesc->attrs;
numAttrs = tupleDesc->natts;
Assert(numAttrs <= MaxHeapAttributeNumber);
for (i = 0; i < numAttrs; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
struct varlena *old_value;
struct varlena *new_value;
* If the old value is stored on disk, check if it has changed so
* we have to delete it later.
*/
- if (att[i]->attlen == -1 && !toast_oldisnull[i] &&
+ if (att->attlen == -1 && !toast_oldisnull[i] &&
VARATT_IS_EXTERNAL_ONDISK(old_value))
{
if (toast_isnull[i] || !VARATT_IS_EXTERNAL_ONDISK(new_value) ||
/*
* Now look at varlena attributes
*/
- if (att[i]->attlen == -1)
+ if (att->attlen == -1)
{
/*
* If the table's attribute says PLAIN always, force it so.
*/
- if (att[i]->attstorage == 'p')
+ if (att->attstorage == 'p')
toast_action[i] = 'p';
/*
if (VARATT_IS_EXTERNAL(new_value))
{
toast_oldexternal[i] = new_value;
- if (att[i]->attstorage == 'p')
+ if (att->attstorage == 'p')
new_value = heap_tuple_untoast_attr(new_value);
else
new_value = heap_tuple_fetch_attr(new_value);
*/
for (i = 0; i < numAttrs; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
+
if (toast_action[i] != ' ')
continue;
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
continue;
- if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
+ if (att->attstorage != 'x' && att->attstorage != 'e')
continue;
if (toast_sizes[i] > biggest_size)
{
* Attempt to compress it inline, if it has attstorage 'x'
*/
i = biggest_attno;
- if (att[i]->attstorage == 'x')
+ if (TupleDescAttr(tupleDesc, i)->attstorage == 'x')
{
old_value = toast_values[i];
new_value = toast_compress_datum(old_value);
*/
for (i = 0; i < numAttrs; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
+
if (toast_action[i] == 'p')
continue;
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
- if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
+ if (att->attstorage != 'x' && att->attstorage != 'e')
continue;
if (toast_sizes[i] > biggest_size)
{
continue; /* can't happen, toast_action would be 'p' */
if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
continue;
- if (att[i]->attstorage != 'm')
+ if (TupleDescAttr(tupleDesc, i)->attstorage != 'm')
continue;
if (toast_sizes[i] > biggest_size)
{
continue;
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
- if (att[i]->attstorage != 'm')
+ if (TupleDescAttr(tupleDesc, i)->attstorage != 'm')
continue;
if (toast_sizes[i] > biggest_size)
{
toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc)
{
HeapTuple new_tuple;
- Form_pg_attribute *att = tupleDesc->attrs;
int numAttrs = tupleDesc->natts;
int i;
Datum toast_values[MaxTupleAttributeNumber];
/*
* Look at non-null varlena attributes
*/
- if (!toast_isnull[i] && att[i]->attlen == -1)
+ if (!toast_isnull[i] && TupleDescAttr(tupleDesc, i)->attlen == -1)
{
struct varlena *new_value;
int32 new_data_len;
int32 new_tuple_len;
HeapTupleData tmptup;
- Form_pg_attribute *att = tupleDesc->attrs;
int numAttrs = tupleDesc->natts;
int i;
bool has_nulls = false;
*/
if (toast_isnull[i])
has_nulls = true;
- else if (att[i]->attlen == -1)
+ else if (TupleDescAttr(tupleDesc, i)->attlen == -1)
{
struct varlena *new_value;
bool *isnull)
{
HeapTuple new_tuple;
- Form_pg_attribute *att = tupleDesc->attrs;
int numAttrs = tupleDesc->natts;
int num_to_free;
int i;
/*
* Look at non-null varlena attributes
*/
- if (!isnull[i] && att[i]->attlen == -1)
+ if (!isnull[i] && TupleDescAttr(tupleDesc, i)->attlen == -1)
{
struct varlena *new_value;
* tupdesc. We pass this to the opclass config function so that
* polymorphic opclasses are possible.
*/
- atttype = index->rd_att->attrs[0]->atttypid;
+ atttype = TupleDescAttr(index->rd_att, 0)->atttypid;
/* Call the config function to get config info for the opclass */
in.attType = atttype;
if (attrtypes[i] == NULL)
attrtypes[i] = AllocateAttribute();
memmove((char *) attrtypes[i],
- (char *) boot_reldesc->rd_att->attrs[i],
+ (char *) TupleDescAttr(boot_reldesc->rd_att, i),
ATTRIBUTE_FIXED_PART_SIZE);
{
elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
- typoid = boot_reldesc->rd_att->attrs[i]->atttypid;
+ typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
boot_get_type_io_data(typoid,
&typlen, &typbyval, &typalign,
{
elog(DEBUG4, "inserting column %d NULL", i);
Assert(i >= 0 && i < MAXATTR);
- if (boot_reldesc->rd_att->attrs[i]->attnotnull)
+ if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
elog(ERROR,
"NULL value specified for not-null column \"%s\" of relation \"%s\"",
- NameStr(boot_reldesc->rd_att->attrs[i]->attname),
+ NameStr(TupleDescAttr(boot_reldesc->rd_att, i)->attname),
RelationGetRelationName(boot_reldesc));
values[i] = PointerGetDatum(NULL);
Nulls[i] = true;
{
for (i = 0; i < natts; i++)
{
- if (SystemAttributeByName(NameStr(tupdesc->attrs[i]->attname),
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+
+ if (SystemAttributeByName(NameStr(attr->attname),
tupdesc->tdhasoid) != NULL)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_COLUMN),
errmsg("column name \"%s\" conflicts with a system column name",
- NameStr(tupdesc->attrs[i]->attname))));
+ NameStr(attr->attname))));
}
}
{
for (j = 0; j < i; j++)
{
- if (strcmp(NameStr(tupdesc->attrs[j]->attname),
- NameStr(tupdesc->attrs[i]->attname)) == 0)
+ if (strcmp(NameStr(TupleDescAttr(tupdesc, j)->attname),
+ NameStr(TupleDescAttr(tupdesc, i)->attname)) == 0)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_COLUMN),
errmsg("column name \"%s\" specified more than once",
- NameStr(tupdesc->attrs[j]->attname))));
+ NameStr(TupleDescAttr(tupdesc, j)->attname))));
}
}
*/
for (i = 0; i < natts; i++)
{
- CheckAttributeType(NameStr(tupdesc->attrs[i]->attname),
- tupdesc->attrs[i]->atttypid,
- tupdesc->attrs[i]->attcollation,
+ CheckAttributeType(NameStr(TupleDescAttr(tupdesc, i)->attname),
+ TupleDescAttr(tupdesc, i)->atttypid,
+ TupleDescAttr(tupdesc, i)->attcollation,
NIL, /* assume we're creating a new rowtype */
allow_system_table_mods);
}
for (i = 0; i < tupdesc->natts; i++)
{
- Form_pg_attribute attr = tupdesc->attrs[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
if (attr->attisdropped)
continue;
*/
for (i = 0; i < natts; i++)
{
- attr = tupdesc->attrs[i];
+ attr = TupleDescAttr(tupdesc, i);
/* Fill in the correct relation OID */
attr->attrelid = new_rel_oid;
/* Make sure these are OK, too */
foreach(cell, newColDefaults)
{
RawColumnDefault *colDef = (RawColumnDefault *) lfirst(cell);
- Form_pg_attribute atp = rel->rd_att->attrs[colDef->attnum - 1];
+ Form_pg_attribute atp = TupleDescAttr(rel->rd_att, colDef->attnum - 1);
Oid defOid;
expr = cookDefault(pstate, colDef->raw_default,
for (i = 0; i < numatts; i++)
{
AttrNumber atnum = indexInfo->ii_KeyAttrNumbers[i];
- Form_pg_attribute to = indexTupDesc->attrs[i];
+ Form_pg_attribute to = TupleDescAttr(indexTupDesc, i);
HeapTuple tuple;
Form_pg_type typeTup;
Form_pg_opclass opclassTup;
*/
if (atnum > natts) /* safety check */
elog(ERROR, "invalid column number %d", atnum);
- from = heapTupDesc->attrs[AttrNumberGetAttrOffset(atnum)];
+ from = TupleDescAttr(heapTupDesc,
+ AttrNumberGetAttrOffset(atnum));
}
/*
tupleDescriptor = RelationGetDescr(indexRelation);
for (i = 0; i < numatts; i += 1)
- tupleDescriptor->attrs[i]->attrelid = indexoid;
+ TupleDescAttr(tupleDescriptor, i)->attrelid = indexoid;
}
/* ----------------------------------------------------------------
for (i = 0; i < numatts; i++)
{
+ Form_pg_attribute attr = TupleDescAttr(indexTupDesc, i);
+
/*
* There used to be very grotty code here to set these fields, but I
* think it's unnecessary. They should be set already.
*/
- Assert(indexTupDesc->attrs[i]->attnum == i + 1);
- Assert(indexTupDesc->attrs[i]->attcacheoff == -1);
+ Assert(attr->attnum == i + 1);
+ Assert(attr->attcacheoff == -1);
- InsertPgAttributeTuple(pg_attribute, indexTupDesc->attrs[i], indstate);
+ InsertPgAttributeTuple(pg_attribute, attr, indstate);
}
CatalogCloseIndexes(indstate);
* toast :-(. This is essential for chunk_data because type bytea is
* toastable; hit the other two just to be sure.
*/
- tupdesc->attrs[0]->attstorage = 'p';
- tupdesc->attrs[1]->attstorage = 'p';
- tupdesc->attrs[2]->attstorage = 'p';
+ TupleDescAttr(tupdesc, 0)->attstorage = 'p';
+ TupleDescAttr(tupdesc, 1)->attstorage = 'p';
+ TupleDescAttr(tupdesc, 2)->attstorage = 'p';
/*
* Toast tables for regular relations go in pg_toast; those for temp
bool maxlength_unknown = false;
bool has_toastable_attrs = false;
TupleDesc tupdesc;
- Form_pg_attribute *att;
int32 tuple_length;
int i;
tupdesc = rel->rd_att;
- att = tupdesc->attrs;
for (i = 0; i < tupdesc->natts; i++)
{
- if (att[i]->attisdropped)
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
+ if (att->attisdropped)
continue;
- data_length = att_align_nominal(data_length, att[i]->attalign);
- if (att[i]->attlen > 0)
+ data_length = att_align_nominal(data_length, att->attalign);
+ if (att->attlen > 0)
{
/* Fixed-length types are never toastable */
- data_length += att[i]->attlen;
+ data_length += att->attlen;
}
else
{
- int32 maxlen = type_maximum_size(att[i]->atttypid,
- att[i]->atttypmod);
+ int32 maxlen = type_maximum_size(att->atttypid,
+ att->atttypmod);
if (maxlen < 0)
maxlength_unknown = true;
else
data_length += maxlen;
- if (att[i]->attstorage != 'p')
+ if (att->attstorage != 'p')
has_toastable_attrs = true;
}
}
static VacAttrStats *
examine_attribute(Relation onerel, int attnum, Node *index_expr)
{
- Form_pg_attribute attr = onerel->rd_att->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(onerel->rd_att, attnum - 1);
HeapTuple typtuple;
VacAttrStats *stats;
int i;
/* Be sure to null out any dropped columns */
for (i = 0; i < newTupDesc->natts; i++)
{
- if (newTupDesc->attrs[i]->attisdropped)
+ if (TupleDescAttr(newTupDesc, i)->attisdropped)
isnull[i] = true;
}
foreach(cur, attnums)
{
int attnum = lfirst_int(cur);
+ Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1);
if (!list_member_int(cstate->attnumlist, attnum))
ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("FORCE_QUOTE column \"%s\" not referenced by COPY",
- NameStr(tupDesc->attrs[attnum - 1]->attname))));
+ NameStr(attr->attname))));
cstate->force_quote_flags[attnum - 1] = true;
}
}
foreach(cur, attnums)
{
int attnum = lfirst_int(cur);
+ Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1);
if (!list_member_int(cstate->attnumlist, attnum))
ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("FORCE_NOT_NULL column \"%s\" not referenced by COPY",
- NameStr(tupDesc->attrs[attnum - 1]->attname))));
+ NameStr(attr->attname))));
cstate->force_notnull_flags[attnum - 1] = true;
}
}
foreach(cur, attnums)
{
int attnum = lfirst_int(cur);
+ Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1);
if (!list_member_int(cstate->attnumlist, attnum))
ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("FORCE_NULL column \"%s\" not referenced by COPY",
- NameStr(tupDesc->attrs[attnum - 1]->attname))));
+ NameStr(attr->attname))));
cstate->force_null_flags[attnum - 1] = true;
}
}
foreach(cur, attnums)
{
int attnum = lfirst_int(cur);
+ Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1);
if (!list_member_int(cstate->attnumlist, attnum))
ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg_internal("selected column \"%s\" not referenced by COPY",
- NameStr(tupDesc->attrs[attnum - 1]->attname))));
+ NameStr(attr->attname))));
cstate->convert_select_flags[attnum - 1] = true;
}
}
{
TupleDesc tupDesc;
int num_phys_attrs;
- Form_pg_attribute *attr;
ListCell *cur;
uint64 processed;
tupDesc = RelationGetDescr(cstate->rel);
else
tupDesc = cstate->queryDesc->tupDesc;
- attr = tupDesc->attrs;
num_phys_attrs = tupDesc->natts;
cstate->null_print_client = cstate->null_print; /* default */
int attnum = lfirst_int(cur);
Oid out_func_oid;
bool isvarlena;
+ Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1);
if (cstate->binary)
- getTypeBinaryOutputInfo(attr[attnum - 1]->atttypid,
+ getTypeBinaryOutputInfo(attr->atttypid,
&out_func_oid,
&isvarlena);
else
- getTypeOutputInfo(attr[attnum - 1]->atttypid,
+ getTypeOutputInfo(attr->atttypid,
&out_func_oid,
&isvarlena);
fmgr_info(out_func_oid, &cstate->out_functions[attnum - 1]);
CopySendChar(cstate, cstate->delim[0]);
hdr_delim = true;
- colname = NameStr(attr[attnum - 1]->attname);
+ colname = NameStr(TupleDescAttr(tupDesc, attnum - 1)->attname);
CopyAttributeOutCSV(cstate, colname, false,
list_length(cstate->attnumlist) == 1);
CopyState cstate;
bool pipe = (filename == NULL);
TupleDesc tupDesc;
- Form_pg_attribute *attr;
AttrNumber num_phys_attrs,
num_defaults;
FmgrInfo *in_functions;
cstate->range_table = pstate->p_rtable;
tupDesc = RelationGetDescr(cstate->rel);
- attr = tupDesc->attrs;
num_phys_attrs = tupDesc->natts;
num_defaults = 0;
volatile_defexprs = false;
for (attnum = 1; attnum <= num_phys_attrs; attnum++)
{
+ Form_pg_attribute att = TupleDescAttr(tupDesc, attnum - 1);
+
/* We don't need info for dropped attributes */
- if (attr[attnum - 1]->attisdropped)
+ if (att->attisdropped)
continue;
/* Fetch the input function and typioparam info */
if (cstate->binary)
- getTypeBinaryInputInfo(attr[attnum - 1]->atttypid,
+ getTypeBinaryInputInfo(att->atttypid,
&in_func_oid, &typioparams[attnum - 1]);
else
- getTypeInputInfo(attr[attnum - 1]->atttypid,
+ getTypeInputInfo(att->atttypid,
&in_func_oid, &typioparams[attnum - 1]);
fmgr_info(in_func_oid, &in_functions[attnum - 1]);
Datum *values, bool *nulls, Oid *tupleOid)
{
TupleDesc tupDesc;
- Form_pg_attribute *attr;
AttrNumber num_phys_attrs,
attr_count,
num_defaults = cstate->num_defaults;
ExprState **defexprs = cstate->defexprs;
tupDesc = RelationGetDescr(cstate->rel);
- attr = tupDesc->attrs;
num_phys_attrs = tupDesc->natts;
attr_count = list_length(cstate->attnumlist);
nfields = file_has_oids ? (attr_count + 1) : attr_count;
{
int attnum = lfirst_int(cur);
int m = attnum - 1;
+ Form_pg_attribute att = TupleDescAttr(tupDesc, m);
if (fieldno >= fldct)
ereport(ERROR,
(errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
errmsg("missing data for column \"%s\"",
- NameStr(attr[m]->attname))));
+ NameStr(att->attname))));
string = field_strings[fieldno++];
if (cstate->convert_select_flags &&
}
}
- cstate->cur_attname = NameStr(attr[m]->attname);
+ cstate->cur_attname = NameStr(att->attname);
cstate->cur_attval = string;
values[m] = InputFunctionCall(&in_functions[m],
string,
typioparams[m],
- attr[m]->atttypmod);
+ att->atttypmod);
if (string != NULL)
nulls[m] = false;
cstate->cur_attname = NULL;
{
int attnum = lfirst_int(cur);
int m = attnum - 1;
+ Form_pg_attribute att = TupleDescAttr(tupDesc, m);
- cstate->cur_attname = NameStr(attr[m]->attname);
+ cstate->cur_attname = NameStr(att->attname);
i++;
values[m] = CopyReadBinaryAttribute(cstate,
i,
&in_functions[m],
typioparams[m],
- attr[m]->atttypmod,
+ att->atttypmod,
&nulls[m]);
cstate->cur_attname = NULL;
}
if (attnamelist == NIL)
{
/* Generate default column list */
- Form_pg_attribute *attr = tupDesc->attrs;
int attr_count = tupDesc->natts;
int i;
for (i = 0; i < attr_count; i++)
{
- if (attr[i]->attisdropped)
+ if (TupleDescAttr(tupDesc, i)->attisdropped)
continue;
attnums = lappend_int(attnums, i + 1);
}
attnum = InvalidAttrNumber;
for (i = 0; i < tupDesc->natts; i++)
{
- if (tupDesc->attrs[i]->attisdropped)
+ Form_pg_attribute att = TupleDescAttr(tupDesc, i);
+
+ if (att->attisdropped)
continue;
- if (namestrcmp(&(tupDesc->attrs[i]->attname), name) == 0)
+ if (namestrcmp(&(att->attname), name) == 0)
{
- attnum = tupDesc->attrs[i]->attnum;
+ attnum = att->attnum;
break;
}
}
lc = list_head(into->colNames);
for (attnum = 0; attnum < typeinfo->natts; attnum++)
{
- Form_pg_attribute attribute = typeinfo->attrs[attnum];
+ Form_pg_attribute attribute = TupleDescAttr(typeinfo, attnum);
ColumnDef *col;
char *colname;
for (i = 0; i < old_natts; i++)
{
if (IsPolymorphicType(get_opclass_input_type(classObjectId[i])) &&
- irel->rd_att->attrs[i]->atttypid != typeObjectId[i])
+ TupleDescAttr(irel->rd_att, i)->atttypid != typeObjectId[i])
{
ret = false;
break;
op_input_types(indexInfo->ii_ExclusionOps[i], &left, &right);
if ((IsPolymorphicType(left) || IsPolymorphicType(right)) &&
- irel->rd_att->attrs[i]->atttypid != typeObjectId[i])
+ TupleDescAttr(irel->rd_att, i)->atttypid != typeObjectId[i])
{
ret = false;
break;
for (i = 0; i < numatts; i++)
{
int attnum = indexStruct->indkey.values[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
Oid type;
Oid op;
const char *colname;
if (foundUniqueIndex)
appendStringInfoString(&querybuf, " AND ");
- colname = quote_identifier(NameStr((tupdesc->attrs[attnum - 1])->attname));
+ colname = quote_identifier(NameStr(attr->attname));
appendStringInfo(&querybuf, "newdata.%s ", colname);
type = attnumTypeId(matviewRel, attnum);
op = lookup_type_cache(type, TYPECACHE_EQ_OPR)->eq_opr;
foreach(listptr, stmt->tableElts)
{
ColumnDef *colDef = lfirst(listptr);
+ Form_pg_attribute attr;
attnum++;
+ attr = TupleDescAttr(descriptor, attnum - 1);
if (colDef->raw_default != NULL)
{
rawEnt->attnum = attnum;
rawEnt->raw_default = colDef->raw_default;
rawDefaults = lappend(rawDefaults, rawEnt);
- descriptor->attrs[attnum - 1]->atthasdef = true;
+ attr->atthasdef = true;
}
else if (colDef->cooked_default != NULL)
{
cooked->inhcount = 0; /* ditto */
cooked->is_no_inherit = false;
cookedDefaults = lappend(cookedDefaults, cooked);
- descriptor->attrs[attnum - 1]->atthasdef = true;
+ attr->atthasdef = true;
}
if (colDef->identity)
- descriptor->attrs[attnum - 1]->attidentity = colDef->identity;
+ attr->attidentity = colDef->identity;
}
/*
for (parent_attno = 1; parent_attno <= tupleDesc->natts;
parent_attno++)
{
- Form_pg_attribute attribute = tupleDesc->attrs[parent_attno - 1];
+ Form_pg_attribute attribute = TupleDescAttr(tupleDesc,
+ parent_attno - 1);
char *attributeName = NameStr(attribute->attname);
int exist_attno;
ColumnDef *def;
*/
for (i = 0; i < newTupDesc->natts; i++)
{
- if (newTupDesc->attrs[i]->attnotnull &&
- !newTupDesc->attrs[i]->attisdropped)
+ Form_pg_attribute attr = TupleDescAttr(newTupDesc, i);
+
+ if (attr->attnotnull && !attr->attisdropped)
notnull_attrs = lappend_int(notnull_attrs, i);
}
if (notnull_attrs)
*/
for (i = 0; i < newTupDesc->natts; i++)
{
- if (newTupDesc->attrs[i]->attisdropped)
+ if (TupleDescAttr(newTupDesc, i)->attisdropped)
dropped_attrs = lappend_int(dropped_attrs, i);
}
int attn = lfirst_int(l);
if (heap_attisnull(tuple, attn + 1))
+ {
+ Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn);
+
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("column \"%s\" contains null values",
- NameStr(newTupDesc->attrs[attn]->attname)),
+ NameStr(attr->attname)),
errtablecol(oldrel, attn + 1)));
+ }
}
foreach(l, tab->constraints)
continue;
rel = relation_open(pg_depend->objid, AccessShareLock);
- att = rel->rd_att->attrs[pg_depend->objsubid - 1];
+ att = TupleDescAttr(rel->rd_att, pg_depend->objsubid - 1);
if (rel->rd_rel->relkind == RELKIND_RELATION ||
rel->rd_rel->relkind == RELKIND_MATVIEW ||
AttrNumber parent_attnum;
parent_attnum = get_attnum(parentId, colName);
- if (tupDesc->attrs[parent_attnum - 1]->attnotnull)
+ if (TupleDescAttr(tupDesc, parent_attnum - 1)->attnotnull)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("column \"%s\" is marked NOT NULL in parent table",
CoercionPathType new_pathtype;
Oid old_castfunc;
Oid new_castfunc;
+ Form_pg_attribute attr = TupleDescAttr(tab->oldDesc,
+ fkattnum[i] - 1);
/*
* Identify coercion pathways from each of the old and new FK-side
* column types to the right (foreign) operand type of the pfeqop.
* We may assume that pg_constraint.conkey is not changing.
*/
- old_fktype = tab->oldDesc->attrs[fkattnum[i] - 1]->atttypid;
+ old_fktype = attr->atttypid;
new_fktype = fktype;
old_pathtype = findFkeyCast(pfeqop_right, old_fktype,
&old_castfunc);
ColumnDef *def = (ColumnDef *) cmd->def;
TypeName *typeName = def->typeName;
HeapTuple heapTup;
- Form_pg_attribute attTup;
+ Form_pg_attribute attTup,
+ attOldTup;
AttrNumber attnum;
HeapTuple typeTuple;
Form_pg_type tform;
colName, RelationGetRelationName(rel))));
attTup = (Form_pg_attribute) GETSTRUCT(heapTup);
attnum = attTup->attnum;
+ attOldTup = TupleDescAttr(tab->oldDesc, attnum - 1);
/* Check for multiple ALTER TYPE on same column --- can't cope */
- if (attTup->atttypid != tab->oldDesc->attrs[attnum - 1]->atttypid ||
- attTup->atttypmod != tab->oldDesc->attrs[attnum - 1]->atttypmod)
+ if (attTup->atttypid != attOldTup->atttypid ||
+ attTup->atttypmod != attOldTup->atttypmod)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot alter type of column \"%s\" twice",
for (parent_attno = 1; parent_attno <= parent_natts; parent_attno++)
{
- Form_pg_attribute attribute = tupleDesc->attrs[parent_attno - 1];
+ Form_pg_attribute attribute = TupleDescAttr(tupleDesc,
+ parent_attno - 1);
char *attributeName = NameStr(attribute->attname);
/* Ignore dropped columns in the parent. */
*table_attname;
/* Get the next non-dropped type attribute. */
- type_attr = typeTupleDesc->attrs[type_attno - 1];
+ type_attr = TupleDescAttr(typeTupleDesc, type_attno - 1);
if (type_attr->attisdropped)
continue;
type_attname = NameStr(type_attr->attname);
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("table is missing column \"%s\"",
type_attname)));
- table_attr = tableTupleDesc->attrs[table_attno++ - 1];
+ table_attr = TupleDescAttr(tableTupleDesc, table_attno - 1);
+ table_attno++;
} while (table_attr->attisdropped);
table_attname = NameStr(table_attr->attname);
/* Any remaining columns at the end of the table had better be dropped. */
for (; table_attno <= tableTupleDesc->natts; table_attno++)
{
- Form_pg_attribute table_attr = tableTupleDesc->attrs[table_attno - 1];
+ Form_pg_attribute table_attr = TupleDescAttr(tableTupleDesc,
+ table_attno - 1);
if (!table_attr->attisdropped)
ereport(ERROR,
errmsg("index \"%s\" cannot be used as replica identity because column %d is a system column",
RelationGetRelationName(indexRel), attno)));
- attr = rel->rd_att->attrs[attno - 1];
+ attr = TupleDescAttr(rel->rd_att, attno - 1);
if (!attr->attnotnull)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
for (i = 1; i <= natts; i++)
{
- Form_pg_attribute att = scanrel->rd_att->attrs[i - 1];
+ Form_pg_attribute att = TupleDescAttr(scanrel->rd_att, i - 1);
if (att->attnotnull && !att->attisdropped)
{
natts = tupleDesc->natts;
for (attno = 1; attno <= natts; attno++)
{
- Form_pg_attribute attribute = tupleDesc->attrs[attno - 1];
+ Form_pg_attribute attribute = TupleDescAttr(tupleDesc, attno - 1);
char *attributeName = NameStr(attribute->attname);
/* Ignore dropped */
for (i = 0; i < rtc->natts; i++)
{
int attnum = rtc->atts[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
if (heap_attisnull(tuple, attnum))
{
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("column \"%s\" of table \"%s\" contains null values",
- NameStr(tupdesc->attrs[attnum - 1]->attname),
+ NameStr(attr->attname),
RelationGetRelationName(testrel)),
errtablecol(testrel, attnum)));
}
Datum d;
bool isNull;
Datum conResult;
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
d = heap_getattr(tuple, attnum, tupdesc, &isNull);
ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION),
errmsg("column \"%s\" of table \"%s\" contains values that violate the new constraint",
- NameStr(tupdesc->attrs[attnum - 1]->attname),
+ NameStr(attr->attname),
RelationGetRelationName(testrel)),
errtablecol(testrel, attnum)));
}
*/
if (pg_depend->objsubid > RelationGetNumberOfAttributes(rtc->rel))
continue;
- pg_att = rtc->rel->rd_att->attrs[pg_depend->objsubid - 1];
+ pg_att = TupleDescAttr(rtc->rel->rd_att, pg_depend->objsubid - 1);
if (pg_att->attisdropped || pg_att->atttypid != domainOid)
continue;
for (i = 0; i < olddesc->natts; i++)
{
- Form_pg_attribute newattr = newdesc->attrs[i];
- Form_pg_attribute oldattr = olddesc->attrs[i];
+ Form_pg_attribute newattr = TupleDescAttr(newdesc, i);
+ Form_pg_attribute oldattr = TupleDescAttr(olddesc, i);
/* XXX msg not right, but we don't support DROP COL on view anyway */
if (newattr->attisdropped != oldattr->attisdropped)
isSafeVar = true; /* can't check, just assume OK */
else if (attnum <= inputDesc->natts)
{
- Form_pg_attribute attr = inputDesc->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(inputDesc, attnum - 1);
/*
* If user attribute is dropped or has a type mismatch, don't
RowExpr *rowexpr = (RowExpr *) node;
int nelems = list_length(rowexpr->args);
TupleDesc tupdesc;
- Form_pg_attribute *attrs;
int i;
ListCell *l;
memset(scratch.d.row.elemnulls, true, sizeof(bool) * nelems);
/* Set up evaluation, skipping any deleted columns */
- attrs = tupdesc->attrs;
i = 0;
foreach(l, rowexpr->args)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
Expr *e = (Expr *) lfirst(l);
- if (!attrs[i]->attisdropped)
+ if (!att->attisdropped)
{
/*
* Guard against ALTER COLUMN TYPE on rowtype since
* typmod too? Not sure we can be sure it'll be the
* same.
*/
- if (exprType((Node *) e) != attrs[i]->atttypid)
+ if (exprType((Node *) e) != att->atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("ROW() column has type %s instead of type %s",
format_type_be(exprType((Node *) e)),
- format_type_be(attrs[i]->atttypid))));
+ format_type_be(att->atttypid))));
}
else
{
elog(ERROR, "attribute number %d exceeds number of columns %d",
attnum, slot_tupdesc->natts);
- attr = slot_tupdesc->attrs[attnum - 1];
+ attr = TupleDescAttr(slot_tupdesc, attnum - 1);
if (attr->attisdropped)
ereport(ERROR,
for (att = 1; att <= tupDesc->natts; att++)
{
/* ignore dropped columns */
- if (tupDesc->attrs[att - 1]->attisdropped)
+ if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
continue;
if (heap_attisnull(&tmptup, att))
{
if (fieldnum > tupDesc->natts) /* should never happen */
elog(ERROR, "attribute number %d exceeds number of columns %d",
fieldnum, tupDesc->natts);
- attr = tupDesc->attrs[fieldnum - 1];
+ attr = TupleDescAttr(tupDesc, fieldnum - 1);
/* Check for dropped column, and force a NULL result if so */
if (attr->attisdropped)
for (i = 0; i < var_tupdesc->natts; i++)
{
- Form_pg_attribute vattr = var_tupdesc->attrs[i];
- Form_pg_attribute sattr = slot_tupdesc->attrs[i];
+ Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
+ Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
if (vattr->atttypid == sattr->atttypid)
continue; /* no worries */
for (i = 0; i < var_tupdesc->natts; i++)
{
- Form_pg_attribute vattr = var_tupdesc->attrs[i];
- Form_pg_attribute sattr = tupleDesc->attrs[i];
+ Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
+ Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
if (!vattr->attisdropped)
continue; /* already checked non-dropped cols */
t = list_head(targetList);
for (i = 0; i < cleanLength; i++)
{
- if (cleanTupType->attrs[i]->attisdropped)
+ if (TupleDescAttr(cleanTupType, i)->attisdropped)
continue; /* map entry is already zero */
for (;;)
{
for (attrChk = 1; attrChk <= natts; attrChk++)
{
- if (tupdesc->attrs[attrChk - 1]->attnotnull &&
- slot_attisnull(slot, attrChk))
+ Form_pg_attribute att = TupleDescAttr(tupdesc, attrChk - 1);
+
+ if (att->attnotnull && slot_attisnull(slot, attrChk))
{
char *val_desc;
Relation orig_rel = rel;
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("null value in column \"%s\" violates not-null constraint",
- NameStr(orig_tupdesc->attrs[attrChk - 1]->attname)),
+ NameStr(att->attname)),
val_desc ? errdetail("Failing row contains %s.", val_desc) : 0,
errtablecol(orig_rel, attrChk)));
}
bool column_perm = false;
char *val;
int vallen;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
/* ignore dropped columns */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
if (!table_perm)
* for the column. If not, omit this column from the error
* message.
*/
- aclresult = pg_attribute_aclcheck(reloid, tupdesc->attrs[i]->attnum,
+ aclresult = pg_attribute_aclcheck(reloid, att->attnum,
GetUserId(), ACL_SELECT);
- if (bms_is_member(tupdesc->attrs[i]->attnum - FirstLowInvalidHeapAttributeNumber,
+ if (bms_is_member(att->attnum - FirstLowInvalidHeapAttributeNumber,
modifiedCols) || aclresult == ACLCHECK_OK)
{
column_perm = any_perm = true;
else
write_comma_collist = true;
- appendStringInfoString(&collist, NameStr(tupdesc->attrs[i]->attname));
+ appendStringInfoString(&collist, NameStr(att->attname));
}
}
Oid foutoid;
bool typisvarlena;
- getTypeOutputInfo(tupdesc->attrs[i]->atttypid,
+ getTypeOutputInfo(att->atttypid,
&foutoid, &typisvarlena);
val = OidOutputFunctionCall(foutoid, slot->tts_values[i]);
}
if (isnull[attrnum])
continue;
- att = desc->attrs[attrnum];
+ att = TupleDescAttr(desc, attrnum);
typentry = lookup_type_cache(att->atttypid, TYPECACHE_EQ_OPR_FINFO);
if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
for (i = 0; i < dst_tupdesc->natts; i++)
{
- Form_pg_attribute dattr = dst_tupdesc->attrs[i];
- Form_pg_attribute sattr = src_tupdesc->attrs[i];
+ Form_pg_attribute dattr = TupleDescAttr(dst_tupdesc, i);
+ Form_pg_attribute sattr = TupleDescAttr(src_tupdesc, i);
if (IsBinaryCoercible(sattr->atttypid, dattr->atttypid))
continue; /* no worries */
/* Check the tlist attributes */
for (attrno = 1; attrno <= numattrs; attrno++)
{
- Form_pg_attribute att_tup = tupdesc->attrs[attrno - 1];
+ Form_pg_attribute att_tup = TupleDescAttr(tupdesc, attrno - 1);
Var *var;
if (tlist_item == NULL)
/* Guard against too-long names list */
if (colno >= typeInfo->natts)
break;
- attr = typeInfo->attrs[colno++];
+ attr = TupleDescAttr(typeInfo, colno);
+ colno++;
/* Ignore empty aliases (these must be for dropped columns) */
if (cname[0] == '\0')
for (i = 0; i < natts; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
/* Ignore dropped attributes */
- if (!tupdesc->attrs[i]->attisdropped)
+ if (!att->attisdropped)
{
- atttypeid = tupdesc->attrs[i]->atttypid;
+ atttypeid = att->atttypid;
getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
fmgr_info(attinfuncid, &attinfuncinfo[i]);
- atttypmods[i] = tupdesc->attrs[i]->atttypmod;
+ atttypmods[i] = att->atttypmod;
}
}
attinmeta->attinfuncs = attinfuncinfo;
/* Call the "in" function for each non-dropped attribute */
for (i = 0; i < natts; i++)
{
- if (!tupdesc->attrs[i]->attisdropped)
+ if (!TupleDescAttr(tupdesc, i)->attisdropped)
{
/* Non-dropped attributes */
dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
attrno = InvalidAttrNumber;
for (i = 0; i < tupDesc->natts; i++)
{
- if (namestrcmp(&(tupDesc->attrs[i]->attname), attname) == 0)
+ Form_pg_attribute att = TupleDescAttr(tupDesc, i);
+
+ if (namestrcmp(&(att->attname), attname) == 0)
{
- attrno = tupDesc->attrs[i]->attnum;
+ attrno = att->attnum;
break;
}
}
errmsg("return type mismatch in function declared to return %s",
format_type_be(rettype)),
errdetail("Final statement returns too many columns.")));
- attr = tupdesc->attrs[colindex - 1];
+ attr = TupleDescAttr(tupdesc, colindex - 1);
if (attr->attisdropped && modifyTargetList)
{
Expr *null_expr;
/* remaining columns in tupdesc had better all be dropped */
for (colindex++; colindex <= tupnatts; colindex++)
{
- if (!tupdesc->attrs[colindex - 1]->attisdropped)
+ if (!TupleDescAttr(tupdesc, colindex - 1)->attisdropped)
ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("return type mismatch in function declared to return %s",
* process_ordered_aggregate_single.)
*/
if (pertrans->numInputs == 1)
+ {
+ Form_pg_attribute attr = TupleDescAttr(pertrans->sortdesc, 0);
+
pertrans->sortstates[aggstate->current_set] =
- tuplesort_begin_datum(pertrans->sortdesc->attrs[0]->atttypid,
+ tuplesort_begin_datum(attr->atttypid,
pertrans->sortOperators[0],
pertrans->sortCollations[0],
pertrans->sortNullsFirst[0],
work_mem, false);
+ }
else
pertrans->sortstates[aggstate->current_set] =
tuplesort_begin_heap(pertrans->sortdesc,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("table row type and query-specified row type do not match"),
errdetail("Query has too many columns.")));
- attr = resultDesc->attrs[attno++];
+ attr = TupleDescAttr(resultDesc, attno);
+ attno++;
if (!attr->attisdropped)
{
found = true;
/* stash away current value */
- Assert(subplan->firstColType == tdesc->attrs[0]->atttypid);
+ Assert(subplan->firstColType == TupleDescAttr(tdesc, 0)->atttypid);
dvalue = slot_getattr(slot, 1, &disnull);
astate = accumArrayResultAny(astate, dvalue, disnull,
subplan->firstColType, oldcontext);
found = true;
/* stash away current value */
- Assert(subplan->firstColType == tdesc->attrs[0]->atttypid);
+ Assert(subplan->firstColType == TupleDescAttr(tdesc, 0)->atttypid);
dvalue = slot_getattr(slot, 1, &disnull);
astate = accumArrayResultAny(astate, dvalue, disnull,
subplan->firstColType, oldcontext);
{
Oid in_funcid;
- getTypeInputInfo(tupdesc->attrs[i]->atttypid,
+ getTypeInputInfo(TupleDescAttr(tupdesc, i)->atttypid,
&in_funcid, &scanstate->typioparams[i]);
fmgr_info(in_funcid, &scanstate->in_functions[i]);
}
foreach(lc1, tstate->colexprs)
{
char *colfilter;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, colno);
if (colno != ordinalitycol)
{
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("column filter expression must not be null"),
errdetail("Filter for column \"%s\" is null.",
- NameStr(tupdesc->attrs[colno]->attname))));
+ NameStr(att->attname))));
colfilter = TextDatumGetCString(value);
}
else
- colfilter = NameStr(tupdesc->attrs[colno]->attname);
+ colfilter = NameStr(att->attname);
routine->SetColumnFilter(tstate, colfilter, colno);
}
*/
for (colno = 0; colno < natts; colno++)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, colno);
+
if (colno == ordinalitycol)
{
/* Fast path for ordinality column */
values[colno] = routine->GetValue(tstate,
colno,
- tupdesc->attrs[colno]->atttypid,
- tupdesc->attrs[colno]->atttypmod,
+ att->atttypid,
+ att->atttypmod,
&isnull);
/* No value? Evaluate and apply the default, if any */
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("null is not allowed in column \"%s\"",
- NameStr(tupdesc->attrs[colno]->attname))));
+ NameStr(att->attname))));
nulls[colno] = isnull;
}
List *exprstatelist;
Datum *values;
bool *isnull;
- Form_pg_attribute *att;
ListCell *lc;
int resind;
*/
values = slot->tts_values;
isnull = slot->tts_isnull;
- att = slot->tts_tupleDescriptor->attrs;
resind = 0;
foreach(lc, exprstatelist)
{
ExprState *estate = (ExprState *) lfirst(lc);
+ Form_pg_attribute attr = TupleDescAttr(slot->tts_tupleDescriptor,
+ resind);
values[resind] = ExecEvalExpr(estate,
econtext,
*/
values[resind] = MakeExpandedObjectReadOnly(values[resind],
isnull[resind],
- att[resind]->attlen);
+ attr->attlen);
resind++;
}
for (res = 0; res < tupdesc->natts; res++)
{
- if (namestrcmp(&tupdesc->attrs[res]->attname, fname) == 0 &&
- !tupdesc->attrs[res]->attisdropped)
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, res);
+
+ if (namestrcmp(&attr->attname, fname) == 0 &&
+ !attr->attisdropped)
return res + 1;
}
}
if (fnumber > 0)
- att = tupdesc->attrs[fnumber - 1];
+ att = TupleDescAttr(tupdesc, fnumber - 1);
else
att = SystemAttributeDefinition(fnumber, true);
return NULL;
if (fnumber > 0)
- typoid = tupdesc->attrs[fnumber - 1]->atttypid;
+ typoid = TupleDescAttr(tupdesc, fnumber - 1)->atttypid;
else
typoid = (SystemAttributeDefinition(fnumber, true))->atttypid;
}
if (fnumber > 0)
- typoid = tupdesc->attrs[fnumber - 1]->atttypid;
+ typoid = TupleDescAttr(tupdesc, fnumber - 1)->atttypid;
else
typoid = (SystemAttributeDefinition(fnumber, true))->atttypid;
}
if (fnumber > 0)
- return tupdesc->attrs[fnumber - 1]->atttypid;
+ return TupleDescAttr(tupdesc, fnumber - 1)->atttypid;
else
return (SystemAttributeDefinition(fnumber, true))->atttypid;
}
appendBinaryStringInfo(&buf, (char *) &tupledesc->tdhasoid, sizeof(bool));
for (i = 0; i < tupledesc->natts; i++)
{
- appendBinaryStringInfo(&buf, (char *) tupledesc->attrs[i],
+ appendBinaryStringInfo(&buf, (char *) TupleDescAttr(tupledesc, i),
sizeof(FormData_pg_attribute));
}
tupledesc->natts * sizeof(TupleRemapInfo *));
for (i = 0; i < tupledesc->natts; i++)
{
- Form_pg_attribute attr = tupledesc->attrs[i];
+ Form_pg_attribute attr = TupleDescAttr(tupledesc, i);
if (attr->attisdropped)
{
{
TStoreState *myState = (TStoreState *) self;
bool needtoast = false;
- Form_pg_attribute *attrs = typeinfo->attrs;
int natts = typeinfo->natts;
int i;
{
for (i = 0; i < natts; i++)
{
- if (attrs[i]->attisdropped)
+ Form_pg_attribute attr = TupleDescAttr(typeinfo, i);
+
+ if (attr->attisdropped)
continue;
- if (attrs[i]->attlen == -1)
+ if (attr->attlen == -1)
{
needtoast = true;
break;
{
TStoreState *myState = (TStoreState *) self;
TupleDesc typeinfo = slot->tts_tupleDescriptor;
- Form_pg_attribute *attrs = typeinfo->attrs;
int natts = typeinfo->natts;
int nfree;
int i;
for (i = 0; i < natts; i++)
{
Datum val = slot->tts_values[i];
+ Form_pg_attribute attr = TupleDescAttr(typeinfo, i);
- if (!attrs[i]->attisdropped &&
- attrs[i]->attlen == -1 &&
- !slot->tts_isnull[i])
+ if (!attr->attisdropped && attr->attlen == -1 && !slot->tts_isnull[i])
{
if (VARATT_IS_EXTERNAL(DatumGetPointer(val)))
{
for (attrno = 1; attrno <= numattrs; attrno++)
{
- Form_pg_attribute att_tup = rel->rd_att->attrs[attrno - 1];
+ Form_pg_attribute att_tup = TupleDescAttr(rel->rd_att, attrno - 1);
TargetEntry *new_tle = NULL;
if (tlist_item != NULL)
Oid attcollation;
int new_attno;
- att = old_tupdesc->attrs[old_attno];
+ att = TupleDescAttr(old_tupdesc, old_attno);
if (att->attisdropped)
{
/* Just put NULL into this list entry */
* notational device to include the assignment into the if-clause.
*/
if (old_attno < newnatts &&
- (att = new_tupdesc->attrs[old_attno]) != NULL &&
+ (att = TupleDescAttr(new_tupdesc, old_attno)) != NULL &&
!att->attisdropped && att->attinhcount != 0 &&
strcmp(attname, NameStr(att->attname)) == 0)
new_attno = old_attno;
{
for (new_attno = 0; new_attno < newnatts; new_attno++)
{
- att = new_tupdesc->attrs[new_attno];
+ att = TupleDescAttr(new_tupdesc, new_attno);
if (!att->attisdropped && att->attinhcount != 0 &&
strcmp(attname, NameStr(att->attname)) == 0)
break;
ReleaseTupleDesc(tupdesc);
return false;
}
- attr = tupdesc->attrs[fieldnum - 1];
+ attr = TupleDescAttr(tupdesc, fieldnum - 1);
if (attr->attisdropped ||
attr->atttypid != expectedtype ||
attr->atttypmod != expectedtypmod ||
for (i = 1; i <= RelationGetNumberOfAttributes(rel); i++)
{
- Form_pg_attribute att = rel->rd_att->attrs[i - 1];
+ Form_pg_attribute att = TupleDescAttr(rel->rd_att, i - 1);
int32 item_width;
if (att->attisdropped)
for (i = 1; i <= natts; i++)
{
- Form_pg_attribute att = relation->rd_att->attrs[i - 1];
+ Form_pg_attribute att = TupleDescAttr(relation->rd_att, i - 1);
if (att->attnotnull && !att->attisdropped)
{
numattrs = RelationGetNumberOfAttributes(relation);
for (attrno = 1; attrno <= numattrs; attrno++)
{
- Form_pg_attribute att_tup = relation->rd_att->attrs[attrno - 1];
+ Form_pg_attribute att_tup = TupleDescAttr(relation->rd_att,
+ attrno - 1);
if (att_tup->attisdropped)
{
att_tup = SystemAttributeDefinition(indexkey,
heapRelation->rd_rel->relhasoids);
else
- att_tup = heapRelation->rd_att->attrs[indexkey - 1];
+ att_tup = TupleDescAttr(heapRelation->rd_att, indexkey - 1);
indexvar = (Expr *) makeVar(varno,
indexkey,
*/
for (attno = 0; attno < targetrel->rd_rel->relnatts; attno++)
{
- Form_pg_attribute attr = targetrel->rd_att->attrs[attno];
+ Form_pg_attribute attr = TupleDescAttr(targetrel->rd_att, attno);
char *name;
if (attr->attisdropped)
Node *expr;
Node *cexpr;
Oid exprtype;
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
/* Fill in NULLs for dropped columns in rowtype */
- if (tupdesc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
{
/*
* can't use atttypid here, but it doesn't really matter what type
cexpr = coerce_to_target_type(pstate,
expr, exprtype,
- tupdesc->attrs[i]->atttypid,
- tupdesc->attrs[i]->atttypmod,
+ attr->atttypid,
+ attr->atttypmod,
ccontext,
COERCE_IMPLICIT_CAST,
-1);
format_type_be(targetTypeId)),
errdetail("Cannot cast type %s to %s in column %d.",
format_type_be(exprtype),
- format_type_be(tupdesc->attrs[i]->atttypid),
+ format_type_be(attr->atttypid),
ucolno),
parser_coercion_errposition(pstate, location, expr)));
newargs = lappend(newargs, cexpr);
for (i = 0; i < tupdesc->natts; i++)
{
- Form_pg_attribute att = tupdesc->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
if (strcmp(funcname, NameStr(att->attname)) == 0 &&
!att->attisdropped)
for (varattno = 0; varattno < maxattrs; varattno++)
{
- Form_pg_attribute attr = tupdesc->attrs[varattno];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, varattno);
Value *attrname;
if (attr->attisdropped)
rte->colcollations = NIL;
for (attno = 1; attno <= tupdesc->natts; ++attno)
{
- if (tupdesc->attrs[attno - 1]->atttypid == InvalidOid &&
- !(tupdesc->attrs[attno - 1]->attisdropped))
+ Form_pg_attribute att = TupleDescAttr(tupdesc, attno - 1);
+
+ if (att->atttypid == InvalidOid &&
+ !(att->attisdropped))
elog(ERROR, "atttypid was invalid for column which has not been dropped from \"%s\"",
rv->relname);
rte->coltypes =
- lappend_oid(rte->coltypes,
- tupdesc->attrs[attno - 1]->atttypid);
+ lappend_oid(rte->coltypes, att->atttypid);
rte->coltypmods =
- lappend_int(rte->coltypmods,
- tupdesc->attrs[attno - 1]->atttypmod);
+ lappend_int(rte->coltypmods, att->atttypmod);
rte->colcollations =
- lappend_oid(rte->colcollations,
- tupdesc->attrs[attno - 1]->attcollation);
+ lappend_oid(rte->colcollations, att->attcollation);
}
/*
Assert(count <= tupdesc->natts);
for (varattno = 0; varattno < count; varattno++)
{
- Form_pg_attribute attr = tupdesc->attrs[varattno];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, varattno);
if (attr->attisdropped)
{
Assert(tupdesc);
Assert(attnum <= tupdesc->natts);
- att_tup = tupdesc->attrs[attnum - 1];
+ att_tup = TupleDescAttr(tupdesc, attnum - 1);
/*
* If dropped column, pretend it ain't there. See
Assert(tupdesc);
Assert(attnum - atts_done <= tupdesc->natts);
- att_tup = tupdesc->attrs[attnum - atts_done - 1];
+ att_tup = TupleDescAttr(tupdesc,
+ attnum - atts_done - 1);
return att_tup->attisdropped;
}
/* Otherwise, it can't have any dropped columns */
for (i = 0; i < rd->rd_rel->relnatts; i++)
{
- Form_pg_attribute att = rd->rd_att->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(rd->rd_att, i);
if (namestrcmp(&(att->attname), attname) == 0 && !att->attisdropped)
return i + 1;
}
if (attid > rd->rd_att->natts)
elog(ERROR, "invalid attribute number %d", attid);
- return &rd->rd_att->attrs[attid - 1]->attname;
+ return &TupleDescAttr(rd->rd_att, attid - 1)->attname;
}
/*
}
if (attid > rd->rd_att->natts)
elog(ERROR, "invalid attribute number %d", attid);
- return rd->rd_att->attrs[attid - 1]->atttypid;
+ return TupleDescAttr(rd->rd_att, attid - 1)->atttypid;
}
/*
}
if (attid > rd->rd_att->natts)
elog(ERROR, "invalid attribute number %d", attid);
- return rd->rd_att->attrs[attid - 1]->attcollation;
+ return TupleDescAttr(rd->rd_att, attid - 1)->attcollation;
}
/*
colname),
parser_errposition(pstate, location)));
attrtype = attnumTypeId(rd, attrno);
- attrtypmod = rd->rd_att->attrs[attrno - 1]->atttypmod;
- attrcollation = rd->rd_att->attrs[attrno - 1]->attcollation;
+ attrtypmod = TupleDescAttr(rd->rd_att, attrno - 1)->atttypmod;
+ attrcollation = TupleDescAttr(rd->rd_att, attrno - 1)->attcollation;
/*
* If the expression is a DEFAULT placeholder, insert the attribute's
/*
* Generate default column list for INSERT.
*/
- Form_pg_attribute *attr = pstate->p_target_relation->rd_att->attrs;
int numcol = pstate->p_target_relation->rd_rel->relnatts;
int i;
for (i = 0; i < numcol; i++)
{
ResTarget *col;
+ Form_pg_attribute attr;
- if (attr[i]->attisdropped)
+ attr = TupleDescAttr(pstate->p_target_relation->rd_att, i);
+
+ if (attr->attisdropped)
continue;
col = makeNode(ResTarget);
- col->name = pstrdup(NameStr(attr[i]->attname));
+ col->name = pstrdup(NameStr(attr->attname));
col->indirection = NIL;
col->val = NULL;
col->location = -1;
numAttrs = tupleDesc->natts;
for (i = 0; i < numAttrs; i++)
{
- Form_pg_attribute att = tupleDesc->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
FieldSelect *fselect;
if (att->attisdropped)
for (parent_attno = 1; parent_attno <= tupleDesc->natts;
parent_attno++)
{
- Form_pg_attribute attribute = tupleDesc->attrs[parent_attno - 1];
+ Form_pg_attribute attribute = TupleDescAttr(tupleDesc,
+ parent_attno - 1);
char *attributeName = NameStr(attribute->attname);
ColumnDef *def;
tupdesc = lookup_rowtype_tupdesc(ofTypeId, -1);
for (i = 0; i < tupdesc->natts; i++)
{
- Form_pg_attribute attr = tupdesc->attrs[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
ColumnDef *n;
if (attr->attisdropped)
const AttrNumber *attmap, int attmap_length)
{
Oid source_relid = RelationGetRelid(source_idx);
- Form_pg_attribute *attrs = RelationGetDescr(source_idx)->attrs;
HeapTuple ht_idxrel;
HeapTuple ht_idx;
HeapTuple ht_am;
{
IndexElem *iparam;
AttrNumber attnum = idxrec->indkey.values[keyno];
+ Form_pg_attribute attr = TupleDescAttr(RelationGetDescr(source_idx),
+ keyno);
int16 opt = source_idx->rd_indoption[keyno];
iparam = makeNode(IndexElem);
}
/* Copy the original index column name */
- iparam->indexcolname = pstrdup(NameStr(attrs[keyno]->attname));
+ iparam->indexcolname = pstrdup(NameStr(attr->attname));
/* Add the collation name, if non-default */
iparam->collation = get_collation(indcollation->values[keyno], keycoltype);
if (attnum > 0)
{
Assert(attnum <= heap_rel->rd_att->natts);
- attform = heap_rel->rd_att->attrs[attnum - 1];
+ attform = TupleDescAttr(heap_rel->rd_att, attnum - 1);
}
else
attform = SystemAttributeDefinition(attnum,
inh->relname)));
for (count = 0; count < rel->rd_att->natts; count++)
{
- Form_pg_attribute inhattr = rel->rd_att->attrs[count];
+ Form_pg_attribute inhattr = TupleDescAttr(rel->rd_att,
+ count);
char *inhname = NameStr(inhattr->attname);
if (inhattr->attisdropped)
for (i = 0; i < desc->natts; i++)
{
- if (desc->attrs[i]->attisdropped)
+ if (TupleDescAttr(desc, i)->attisdropped)
continue;
nliveatts++;
}
{
HeapTuple typtup;
Form_pg_type typclass;
- Form_pg_attribute att = desc->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(desc, i);
char *outputstr;
/* skip dropped columns */
/* send number of live attributes */
for (i = 0; i < desc->natts; i++)
{
- if (desc->attrs[i]->attisdropped)
+ if (TupleDescAttr(desc, i)->attisdropped)
continue;
nliveatts++;
}
/* send the attributes */
for (i = 0; i < desc->natts; i++)
{
- Form_pg_attribute att = desc->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(desc, i);
uint8 flags = 0;
if (att->attisdropped)
for (i = 0; i < desc->natts; i++)
{
int attnum;
+ Form_pg_attribute attr = TupleDescAttr(desc, i);
- if (desc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
{
entry->attrmap[i] = -1;
continue;
}
attnum = logicalrep_rel_att_by_name(remoterel,
- NameStr(desc->attrs[i]->attname));
+ NameStr(attr->attname));
entry->attrmap[i] = attnum;
if (attnum >= 0)
for (natt = 0; natt < desc->natts; natt++)
{
- Form_pg_attribute attr = desc->attrs[natt];
+ Form_pg_attribute attr = TupleDescAttr(desc, natt);
ReorderBufferToastEnt *ent;
struct varlena *varlena;
{
Expr *defexpr;
- if (desc->attrs[attnum]->attisdropped)
+ if (TupleDescAttr(desc, attnum)->attisdropped)
continue;
if (rel->attrmap[attnum] >= 0)
/* Call the "in" function for each non-dropped attribute */
for (i = 0; i < natts; i++)
{
- Form_pg_attribute att = slot->tts_tupleDescriptor->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(slot->tts_tupleDescriptor, i);
int remoteattnum = rel->attrmap[i];
if (!att->attisdropped && remoteattnum >= 0 &&
/* Call the "in" function for each replaced attribute */
for (i = 0; i < natts; i++)
{
- Form_pg_attribute att = slot->tts_tupleDescriptor->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(slot->tts_tupleDescriptor, i);
int remoteattnum = rel->attrmap[i];
if (remoteattnum >= 0 && !replaces[remoteattnum])
*/
for (i = 0; i < desc->natts; i++)
{
- Form_pg_attribute att = desc->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(desc, i);
if (att->attisdropped)
continue;
errmsg("SELECT rule's target list has too many entries") :
errmsg("RETURNING list has too many entries")));
- attr = resultDesc->attrs[i - 1];
+ attr = TupleDescAttr(resultDesc, i - 1);
attname = NameStr(attr->attname);
/*
attrno = old_tle->resno;
if (attrno < 1 || attrno > numattrs)
elog(ERROR, "bogus resno %d in targetlist", attrno);
- att_tup = target_relation->rd_att->attrs[attrno - 1];
+ att_tup = TupleDescAttr(target_relation->rd_att, attrno - 1);
/* put attrno into attrno_list even if it's dropped */
if (attrno_list)
TargetEntry *new_tle = new_tles[attrno - 1];
bool apply_default;
- att_tup = target_relation->rd_att->attrs[attrno - 1];
+ att_tup = TupleDescAttr(target_relation->rd_att, attrno - 1);
/* We can (and must) ignore deleted attributes */
if (att_tup->attisdropped)
build_column_default(Relation rel, int attrno)
{
TupleDesc rd_att = rel->rd_att;
- Form_pg_attribute att_tup = rd_att->attrs[attrno - 1];
+ Form_pg_attribute att_tup = TupleDescAttr(rd_att, attrno - 1);
Oid atttype = att_tup->atttypid;
int32 atttypmod = att_tup->atttypmod;
Node *expr = NULL;
Form_pg_attribute att_tup;
Node *new_expr;
- att_tup = target_relation->rd_att->attrs[attrno - 1];
+ att_tup = TupleDescAttr(target_relation->rd_att, attrno - 1);
if (!att_tup->attisdropped)
new_expr = build_column_default(target_relation, attrno);
char *attname;
JsonTypeCategory tcategory;
Oid outfuncoid;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
if (needsep)
appendStringInfoString(result, sep);
needsep = true;
- attname = NameStr(tupdesc->attrs[i]->attname);
+ attname = NameStr(att->attname);
escape_json(result, attname);
appendStringInfoChar(result, ':');
outfuncoid = InvalidOid;
}
else
- json_categorize_type(tupdesc->attrs[i]->atttypid,
- &tcategory, &outfuncoid);
+ json_categorize_type(att->atttypid, &tcategory, &outfuncoid);
datum_to_json(val, isnull, result, tcategory, outfuncoid, false);
}
JsonbTypeCategory tcategory;
Oid outfuncoid;
JsonbValue v;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
- attname = NameStr(tupdesc->attrs[i]->attname);
+ attname = NameStr(att->attname);
v.type = jbvString;
/* don't need checkStringLen here - can't exceed maximum name length */
outfuncoid = InvalidOid;
}
else
- jsonb_categorize_type(tupdesc->attrs[i]->atttypid,
- &tcategory, &outfuncoid);
+ jsonb_categorize_type(att->atttypid, &tcategory, &outfuncoid);
datum_to_jsonb(val, isnull, result, tcategory, outfuncoid, false);
}
for (i = 0; i < ncolumns; ++i)
{
- Form_pg_attribute att = tupdesc->attrs[i];
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
char *colname = NameStr(att->attname);
JsValue field = {0};
bool found;
/* check that we have an int4 flag column */
if (!tupdesc ||
(nargs + 1) != tupdesc->natts ||
- tupdesc->attrs[nargs]->atttypid != INT4OID)
+ TupleDescAttr(tupdesc, nargs)->atttypid != INT4OID)
elog(ERROR, "type mismatch in hypothetical-set function");
/* check that direct args match in type with aggregated args */
for (i = 0; i < nargs; i++)
{
- if (get_fn_expr_argtype(fcinfo->flinfo, i + 1) != tupdesc->attrs[i]->atttypid)
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+
+ if (get_fn_expr_argtype(fcinfo->flinfo, i + 1) != attr->atttypid)
elog(ERROR, "type mismatch in hypothetical-set function");
}
}
for (i = 0; i < ncolumns; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
ColumnIOData *column_info = &my_extra->columns[i];
- Oid column_type = tupdesc->attrs[i]->atttypid;
+ Oid column_type = att->atttypid;
char *column_data;
/* Ignore dropped columns in datatype, but fill with nulls */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
{
values[i] = (Datum) 0;
nulls[i] = true;
values[i] = InputFunctionCall(&column_info->proc,
column_data,
column_info->typioparam,
- tupdesc->attrs[i]->atttypmod);
+ att->atttypmod);
/*
* Prep for next column
for (i = 0; i < ncolumns; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
ColumnIOData *column_info = &my_extra->columns[i];
- Oid column_type = tupdesc->attrs[i]->atttypid;
+ Oid column_type = att->atttypid;
Datum attr;
char *value;
char *tmp;
bool nq;
/* Ignore dropped columns in datatype */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
if (needComma)
validcols = 0;
for (i = 0; i < ncolumns; i++)
{
- if (!tupdesc->attrs[i]->attisdropped)
+ if (!TupleDescAttr(tupdesc, i)->attisdropped)
validcols++;
}
if (usercols != validcols)
/* Process each column */
for (i = 0; i < ncolumns; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
ColumnIOData *column_info = &my_extra->columns[i];
- Oid column_type = tupdesc->attrs[i]->atttypid;
+ Oid column_type = att->atttypid;
Oid coltypoid;
int itemlen;
StringInfoData item_buf;
char csave;
/* Ignore dropped columns in datatype, but fill with nulls */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
{
values[i] = (Datum) 0;
nulls[i] = true;
values[i] = ReceiveFunctionCall(&column_info->proc,
bufptr,
column_info->typioparam,
- tupdesc->attrs[i]->atttypmod);
+ att->atttypmod);
if (bufptr)
{
validcols = 0;
for (i = 0; i < ncolumns; i++)
{
- if (!tupdesc->attrs[i]->attisdropped)
+ if (!TupleDescAttr(tupdesc, i)->attisdropped)
validcols++;
}
pq_sendint(&buf, validcols, 4);
for (i = 0; i < ncolumns; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
ColumnIOData *column_info = &my_extra->columns[i];
- Oid column_type = tupdesc->attrs[i]->atttypid;
+ Oid column_type = att->atttypid;
Datum attr;
bytea *outputbytes;
/* Ignore dropped columns in datatype */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
pq_sendint(&buf, column_type, sizeof(Oid));
i1 = i2 = j = 0;
while (i1 < ncolumns1 || i2 < ncolumns2)
{
+ Form_pg_attribute att1;
+ Form_pg_attribute att2;
TypeCacheEntry *typentry;
Oid collation;
/*
* Skip dropped columns
*/
- if (i1 < ncolumns1 && tupdesc1->attrs[i1]->attisdropped)
+ if (i1 < ncolumns1 && TupleDescAttr(tupdesc1, i1)->attisdropped)
{
i1++;
continue;
}
- if (i2 < ncolumns2 && tupdesc2->attrs[i2]->attisdropped)
+ if (i2 < ncolumns2 && TupleDescAttr(tupdesc2, i2)->attisdropped)
{
i2++;
continue;
if (i1 >= ncolumns1 || i2 >= ncolumns2)
break; /* we'll deal with mismatch below loop */
+ att1 = TupleDescAttr(tupdesc1, i1);
+ att2 = TupleDescAttr(tupdesc2, i2);
+
/*
* Have two matching columns, they must be same type
*/
- if (tupdesc1->attrs[i1]->atttypid !=
- tupdesc2->attrs[i2]->atttypid)
+ if (att1->atttypid != att2->atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot compare dissimilar column types %s and %s at record column %d",
- format_type_be(tupdesc1->attrs[i1]->atttypid),
- format_type_be(tupdesc2->attrs[i2]->atttypid),
+ format_type_be(att1->atttypid),
+ format_type_be(att2->atttypid),
j + 1)));
/*
* If they're not same collation, we don't complain here, but the
* comparison function might.
*/
- collation = tupdesc1->attrs[i1]->attcollation;
- if (collation != tupdesc2->attrs[i2]->attcollation)
+ collation = att1->attcollation;
+ if (collation != att2->attcollation)
collation = InvalidOid;
/*
*/
typentry = my_extra->columns[j].typentry;
if (typentry == NULL ||
- typentry->type_id != tupdesc1->attrs[i1]->atttypid)
+ typentry->type_id != att1->atttypid)
{
- typentry = lookup_type_cache(tupdesc1->attrs[i1]->atttypid,
+ typentry = lookup_type_cache(att1->atttypid,
TYPECACHE_CMP_PROC_FINFO);
if (!OidIsValid(typentry->cmp_proc_finfo.fn_oid))
ereport(ERROR,
i1 = i2 = j = 0;
while (i1 < ncolumns1 || i2 < ncolumns2)
{
+ Form_pg_attribute att1;
+ Form_pg_attribute att2;
TypeCacheEntry *typentry;
Oid collation;
FunctionCallInfoData locfcinfo;
/*
* Skip dropped columns
*/
- if (i1 < ncolumns1 && tupdesc1->attrs[i1]->attisdropped)
+ if (i1 < ncolumns1 && TupleDescAttr(tupdesc1, i1)->attisdropped)
{
i1++;
continue;
}
- if (i2 < ncolumns2 && tupdesc2->attrs[i2]->attisdropped)
+ if (i2 < ncolumns2 && TupleDescAttr(tupdesc2, i2)->attisdropped)
{
i2++;
continue;
if (i1 >= ncolumns1 || i2 >= ncolumns2)
break; /* we'll deal with mismatch below loop */
+ att1 = TupleDescAttr(tupdesc1, i1);
+ att2 = TupleDescAttr(tupdesc2, i2);
+
/*
* Have two matching columns, they must be same type
*/
- if (tupdesc1->attrs[i1]->atttypid !=
- tupdesc2->attrs[i2]->atttypid)
+ if (att1->atttypid != att2->atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot compare dissimilar column types %s and %s at record column %d",
- format_type_be(tupdesc1->attrs[i1]->atttypid),
- format_type_be(tupdesc2->attrs[i2]->atttypid),
+ format_type_be(att1->atttypid),
+ format_type_be(att2->atttypid),
j + 1)));
/*
* If they're not same collation, we don't complain here, but the
* equality function might.
*/
- collation = tupdesc1->attrs[i1]->attcollation;
- if (collation != tupdesc2->attrs[i2]->attcollation)
+ collation = att1->attcollation;
+ if (collation != att2->attcollation)
collation = InvalidOid;
/*
*/
typentry = my_extra->columns[j].typentry;
if (typentry == NULL ||
- typentry->type_id != tupdesc1->attrs[i1]->atttypid)
+ typentry->type_id != att1->atttypid)
{
- typentry = lookup_type_cache(tupdesc1->attrs[i1]->atttypid,
+ typentry = lookup_type_cache(att1->atttypid,
TYPECACHE_EQ_OPR_FINFO);
if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
ereport(ERROR,
i1 = i2 = j = 0;
while (i1 < ncolumns1 || i2 < ncolumns2)
{
+ Form_pg_attribute att1;
+ Form_pg_attribute att2;
+
/*
* Skip dropped columns
*/
- if (i1 < ncolumns1 && tupdesc1->attrs[i1]->attisdropped)
+ if (i1 < ncolumns1 && TupleDescAttr(tupdesc1, i1)->attisdropped)
{
i1++;
continue;
}
- if (i2 < ncolumns2 && tupdesc2->attrs[i2]->attisdropped)
+ if (i2 < ncolumns2 && TupleDescAttr(tupdesc2, i2)->attisdropped)
{
i2++;
continue;
if (i1 >= ncolumns1 || i2 >= ncolumns2)
break; /* we'll deal with mismatch below loop */
+ att1 = TupleDescAttr(tupdesc1, i1);
+ att2 = TupleDescAttr(tupdesc2, i2);
+
/*
* Have two matching columns, they must be same type
*/
- if (tupdesc1->attrs[i1]->atttypid !=
- tupdesc2->attrs[i2]->atttypid)
+ if (att1->atttypid != att2->atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot compare dissimilar column types %s and %s at record column %d",
- format_type_be(tupdesc1->attrs[i1]->atttypid),
- format_type_be(tupdesc2->attrs[i2]->atttypid),
+ format_type_be(att1->atttypid),
+ format_type_be(att2->atttypid),
j + 1)));
/*
* The same type should have the same length (or both should be
* variable).
*/
- Assert(tupdesc1->attrs[i1]->attlen ==
- tupdesc2->attrs[i2]->attlen);
+ Assert(att1->attlen == att2->attlen);
/*
* We consider two NULLs equal; NULL > not-NULL.
}
/* Compare the pair of elements */
- if (tupdesc1->attrs[i1]->attlen == -1)
+ if (att1->attlen == -1)
{
Size len1,
len2;
if ((Pointer) arg2val != (Pointer) values2[i2])
pfree(arg2val);
}
- else if (tupdesc1->attrs[i1]->attbyval)
+ else if (att1->attbyval)
{
- switch (tupdesc1->attrs[i1]->attlen)
+ switch (att1->attlen)
{
case 1:
if (GET_1_BYTE(values1[i1]) !=
{
cmpresult = memcmp(DatumGetPointer(values1[i1]),
DatumGetPointer(values2[i2]),
- tupdesc1->attrs[i1]->attlen);
+ att1->attlen);
}
if (cmpresult < 0)
i1 = i2 = j = 0;
while (i1 < ncolumns1 || i2 < ncolumns2)
{
+ Form_pg_attribute att1;
+ Form_pg_attribute att2;
+
/*
* Skip dropped columns
*/
- if (i1 < ncolumns1 && tupdesc1->attrs[i1]->attisdropped)
+ if (i1 < ncolumns1 && TupleDescAttr(tupdesc1, i1)->attisdropped)
{
i1++;
continue;
}
- if (i2 < ncolumns2 && tupdesc2->attrs[i2]->attisdropped)
+ if (i2 < ncolumns2 && TupleDescAttr(tupdesc2, i2)->attisdropped)
{
i2++;
continue;
if (i1 >= ncolumns1 || i2 >= ncolumns2)
break; /* we'll deal with mismatch below loop */
+ att1 = TupleDescAttr(tupdesc1, i1);
+ att2 = TupleDescAttr(tupdesc2, i2);
+
/*
* Have two matching columns, they must be same type
*/
- if (tupdesc1->attrs[i1]->atttypid !=
- tupdesc2->attrs[i2]->atttypid)
+ if (att1->atttypid != att2->atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot compare dissimilar column types %s and %s at record column %d",
- format_type_be(tupdesc1->attrs[i1]->atttypid),
- format_type_be(tupdesc2->attrs[i2]->atttypid),
+ format_type_be(att1->atttypid),
+ format_type_be(att2->atttypid),
j + 1)));
/*
}
/* Compare the pair of elements */
- if (tupdesc1->attrs[i1]->attlen == -1)
+ if (att1->attlen == -1)
{
Size len1,
len2;
pfree(arg2val);
}
}
- else if (tupdesc1->attrs[i1]->attbyval)
+ else if (att1->attbyval)
{
- switch (tupdesc1->attrs[i1]->attlen)
+ switch (att1->attlen)
{
case 1:
result = (GET_1_BYTE(values1[i1]) ==
{
result = (memcmp(DatumGetPointer(values1[i1]),
DatumGetPointer(values2[i2]),
- tupdesc1->attrs[i1]->attlen) == 0);
+ att1->attlen) == 0);
}
if (!result)
break;
for (i = 0; i < ncolumns; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+
+ if (attr->attisdropped)
real_colnames[i] = NULL;
else
- real_colnames[i] = pstrdup(NameStr(tupdesc->attrs[i]->attname));
+ real_colnames[i] = pstrdup(NameStr(attr->attname));
}
relation_close(rel, AccessShareLock);
}
* Otherwise, just use what we can find in the TLE.
*/
if (resultDesc && colno <= resultDesc->natts)
- colname = NameStr(resultDesc->attrs[colno - 1]->attname);
+ colname = NameStr(TupleDescAttr(resultDesc, colno - 1)->attname);
else
colname = tle->resname;
Assert(tupleDesc);
/* Got the tupdesc, so we can extract the field name */
Assert(fieldno >= 1 && fieldno <= tupleDesc->natts);
- return NameStr(tupleDesc->attrs[fieldno - 1]->attname);
+ return NameStr(TupleDescAttr(tupleDesc, fieldno - 1)->attname);
}
/* Find appropriate nesting depth */
Assert(tupleDesc);
/* Got the tupdesc, so we can extract the field name */
Assert(fieldno >= 1 && fieldno <= tupleDesc->natts);
- return NameStr(tupleDesc->attrs[fieldno - 1]->attname);
+ return NameStr(TupleDescAttr(tupleDesc, fieldno - 1)->attname);
}
/*
Node *e = (Node *) lfirst(arg);
if (tupdesc == NULL ||
- !tupdesc->attrs[i]->attisdropped)
+ !TupleDescAttr(tupdesc, i)->attisdropped)
{
appendStringInfoString(buf, sep);
/* Whole-row Vars need special treatment here */
{
while (i < tupdesc->natts)
{
- if (!tupdesc->attrs[i]->attisdropped)
+ if (!TupleDescAttr(tupdesc, i)->attisdropped)
{
appendStringInfoString(buf, sep);
appendStringInfoString(buf, "NULL");
for (i = 0; i < natts; i++)
{
- if (strcmp(NameStr(att->attrs[i]->attname), "ctid") == 0)
+ Form_pg_attribute attr = TupleDescAttr(att, i);
+
+ if (strcmp(NameStr(attr->attname), "ctid") == 0)
{
- if (att->attrs[i]->atttypid != TIDOID)
+ if (attr->atttypid != TIDOID)
elog(ERROR, "ctid isn't of type TID");
tididx = i;
break;
for (i = 0; i < tupdesc->natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
+ if (att->attisdropped)
continue;
appendStringInfo(&result,
" <xsd:element name=\"%s\" type=\"%s\"%s></xsd:element>\n",
- map_sql_identifier_to_xml_name(NameStr(tupdesc->attrs[i]->attname),
+ map_sql_identifier_to_xml_name(NameStr(att->attname),
true, false),
- map_sql_type_to_xml_name(tupdesc->attrs[i]->atttypid, -1),
+ map_sql_type_to_xml_name(att->atttypid, -1),
nulls ? " nillable=\"true\"" : " minOccurs=\"0\"");
}
for (i = 0; i < tupdesc->natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
+ if (att->attisdropped)
continue;
- uniquetypes = list_append_unique_oid(uniquetypes,
- tupdesc->attrs[i]->atttypid);
+ uniquetypes = list_append_unique_oid(uniquetypes, att->atttypid);
}
}
if (cache->cc_key[i] > 0) { \
elog(DEBUG2, "CatalogCacheInitializeCache: load %d/%d w/%d, %u", \
i+1, cache->cc_nkeys, cache->cc_key[i], \
- tupdesc->attrs[cache->cc_key[i] - 1]->atttypid); \
+ TupleDescAttr(tupdesc, cache->cc_key[i] - 1)->atttypid); \
} else { \
elog(DEBUG2, "CatalogCacheInitializeCache: load %d/%d w/%d", \
i+1, cache->cc_nkeys, cache->cc_key[i]); \
if (cache->cc_key[i] > 0)
{
- Form_pg_attribute attr = tupdesc->attrs[cache->cc_key[i] - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc,
+ cache->cc_key[i] - 1);
keytype = attr->atttypid;
/* cache key columns should always be NOT NULL */
elog(ERROR, "invalid attribute number %d for %s",
attp->attnum, RelationGetRelationName(relation));
- memcpy(relation->rd_att->attrs[attp->attnum - 1],
+ memcpy(TupleDescAttr(relation->rd_att, attp->attnum - 1),
attp,
ATTRIBUTE_FIXED_PART_SIZE);
int i;
for (i = 0; i < relation->rd_rel->relnatts; i++)
- Assert(relation->rd_att->attrs[i]->attcacheoff == -1);
+ Assert(TupleDescAttr(relation->rd_att, i)->attcacheoff == -1);
}
#endif
* for attnum=1 that used to exist in fastgetattr() and index_getattr().
*/
if (relation->rd_rel->relnatts > 0)
- relation->rd_att->attrs[0]->attcacheoff = 0;
+ TupleDescAttr(relation->rd_att, 0)->attcacheoff = 0;
/*
* Set up constraint/default info
/* Collect type information */
if (attno != 0)
{
- key->parttypid[i] = relation->rd_att->attrs[attno - 1]->atttypid;
- key->parttypmod[i] = relation->rd_att->attrs[attno - 1]->atttypmod;
- key->parttypcoll[i] = relation->rd_att->attrs[attno - 1]->attcollation;
+ Form_pg_attribute att = TupleDescAttr(relation->rd_att, attno - 1);
+
+ key->parttypid[i] = att->atttypid;
+ key->parttypmod[i] = att->atttypmod;
+ key->parttypcoll[i] = att->attcollation;
}
else
{
has_not_null = false;
for (i = 0; i < natts; i++)
{
- memcpy(relation->rd_att->attrs[i],
+ memcpy(TupleDescAttr(relation->rd_att, i),
&attrs[i],
ATTRIBUTE_FIXED_PART_SIZE);
has_not_null |= attrs[i].attnotnull;
/* make sure attcacheoff is valid */
- relation->rd_att->attrs[i]->attcacheoff = -1;
+ TupleDescAttr(relation->rd_att, i)->attcacheoff = -1;
}
/* initialize first attribute's attcacheoff, cf RelationBuildTupleDesc */
- relation->rd_att->attrs[0]->attcacheoff = 0;
+ TupleDescAttr(relation->rd_att, 0)->attcacheoff = 0;
/* mark not-null status */
if (has_not_null)
/*
* initialize relation id from info in att array (my, this is ugly)
*/
- RelationGetRelid(relation) = relation->rd_att->attrs[0]->attrelid;
+ RelationGetRelid(relation) = TupleDescAttr(relation->rd_att, 0)->attrelid;
/*
* All relations made with formrdesc are mapped. This is necessarily so
has_not_null = false;
for (i = 0; i < natts; i++)
{
- rel->rd_att->attrs[i]->attidentity = tupDesc->attrs[i]->attidentity;
- rel->rd_att->attrs[i]->attnotnull = tupDesc->attrs[i]->attnotnull;
- has_not_null |= tupDesc->attrs[i]->attnotnull;
+ Form_pg_attribute satt = TupleDescAttr(tupDesc, i);
+ Form_pg_attribute datt = TupleDescAttr(rel->rd_att, i);
+
+ datt->attidentity = satt->attidentity;
+ datt->attnotnull = satt->attnotnull;
+ has_not_null |= satt->attnotnull;
}
if (has_not_null)
RelationGetRelid(rel) = relid;
for (i = 0; i < natts; i++)
- rel->rd_att->attrs[i]->attrelid = relid;
+ TupleDescAttr(rel->rd_att, i)->attrelid = relid;
rel->rd_rel->reltablespace = reltablespace;
for (i = 0; i < natts; i++)
{
- memcpy(result->attrs[i], &attrs[i], ATTRIBUTE_FIXED_PART_SIZE);
+ memcpy(TupleDescAttr(result, i), &attrs[i], ATTRIBUTE_FIXED_PART_SIZE);
/* make sure attcacheoff is valid */
- result->attrs[i]->attcacheoff = -1;
+ TupleDescAttr(result, i)->attcacheoff = -1;
}
/* initialize first attribute's attcacheoff, cf RelationBuildTupleDesc */
- result->attrs[0]->attcacheoff = 0;
+ TupleDescAttr(result, 0)->attcacheoff = 0;
/* Note: we don't bother to set up a TupleConstr entry */
while (HeapTupleIsValid(htup = systable_getnext(adscan)))
{
Form_pg_attrdef adform = (Form_pg_attrdef) GETSTRUCT(htup);
+ Form_pg_attribute attr = TupleDescAttr(relation->rd_att, adform->adnum - 1);
for (i = 0; i < ndef; i++)
{
continue;
if (attrdef[i].adbin != NULL)
elog(WARNING, "multiple attrdef records found for attr %s of rel %s",
- NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname),
+ NameStr(attr->attname),
RelationGetRelationName(relation));
else
found++;
adrel->rd_att, &isnull);
if (isnull)
elog(WARNING, "null adbin for attr %s of rel %s",
- NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname),
+ NameStr(attr->attname),
RelationGetRelationName(relation));
else
{
/* Use reldesc if it's a user attribute, else consult the catalogs */
if (attnum > 0 && attnum <= reldesc->natts)
- colname = NameStr(reldesc->attrs[attnum - 1]->attname);
+ colname = NameStr(TupleDescAttr(reldesc, attnum - 1)->attname);
else
colname = get_relid_attribute_name(RelationGetRelid(rel), attnum);
has_not_null = false;
for (i = 0; i < relform->relnatts; i++)
{
+ Form_pg_attribute attr = TupleDescAttr(rel->rd_att, i);
+
if (fread(&len, 1, sizeof(len), fp) != sizeof(len))
goto read_failed;
if (len != ATTRIBUTE_FIXED_PART_SIZE)
goto read_failed;
- if (fread(rel->rd_att->attrs[i], 1, len, fp) != len)
+ if (fread(attr, 1, len, fp) != len)
goto read_failed;
- has_not_null |= rel->rd_att->attrs[i]->attnotnull;
+ has_not_null |= attr->attnotnull;
}
/* next read the access method specific field */
/* next, do all the attribute tuple form data entries */
for (i = 0; i < relform->relnatts; i++)
{
- write_item(rel->rd_att->attrs[i], ATTRIBUTE_FIXED_PART_SIZE, fp);
+ write_item(TupleDescAttr(rel->rd_att, i),
+ ATTRIBUTE_FIXED_PART_SIZE, fp);
}
/* next, do the access method specific field */
for (i = 0; i < tupdesc->natts; i++)
{
TypeCacheEntry *fieldentry;
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
- if (tupdesc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
continue;
- fieldentry = lookup_type_cache(tupdesc->attrs[i]->atttypid,
+ fieldentry = lookup_type_cache(attr->atttypid,
TYPECACHE_EQ_OPR |
TYPECACHE_CMP_PROC);
if (!OidIsValid(fieldentry->eq_opr))
{
if (i >= REC_HASH_KEYS)
break;
- hashkey[i] = tupDesc->attrs[i]->atttypid;
+ hashkey[i] = TupleDescAttr(tupDesc, i)->atttypid;
}
recentry = (RecordCacheEntry *) hash_search(RecordCacheHash,
(void *) hashkey,
/* See if there are any polymorphic outputs; quick out if not */
for (i = 0; i < natts; i++)
{
- switch (tupdesc->attrs[i]->atttypid)
+ switch (TupleDescAttr(tupdesc, i)->atttypid)
{
case ANYELEMENTOID:
have_anyelement_result = true;
/* And finally replace the tuple column types as needed */
for (i = 0; i < natts; i++)
{
- switch (tupdesc->attrs[i]->atttypid)
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
+ switch (att->atttypid)
{
case ANYELEMENTOID:
case ANYNONARRAYOID:
case ANYENUMOID:
TupleDescInitEntry(tupdesc, i + 1,
- NameStr(tupdesc->attrs[i]->attname),
+ NameStr(att->attname),
anyelement_type,
-1,
0);
break;
case ANYARRAYOID:
TupleDescInitEntry(tupdesc, i + 1,
- NameStr(tupdesc->attrs[i]->attname),
+ NameStr(att->attname),
anyarray_type,
-1,
0);
break;
case ANYRANGEOID:
TupleDescInitEntry(tupdesc, i + 1,
- NameStr(tupdesc->attrs[i]->attname),
+ NameStr(att->attname),
anyrange_type,
-1,
0);
for (varattno = 0; varattno < natts; varattno++)
{
char *label = strVal(list_nth(colaliases, varattno));
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, varattno);
if (label != NULL)
- namestrcpy(&(tupdesc->attrs[varattno]->attname), label);
+ namestrcpy(&(attr->attname), label);
}
/* The tuple type is now an anonymous record type */
* Check to make sure we have a reasonable tuple descriptor
*/
if (tupdesc->natts != 2 ||
- tupdesc->attrs[0]->atttypid != TEXTOID ||
- tupdesc->attrs[1]->atttypid != TEXTOID)
+ TupleDescAttr(tupdesc, 0)->atttypid != TEXTOID ||
+ TupleDescAttr(tupdesc, 1)->atttypid != TEXTOID)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("query-specified return tuple and "
(*(isnull) = false), \
HeapTupleNoNulls(tup) ? \
( \
- (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
+ TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff >= 0 ? \
( \
- fetchatt((tupleDesc)->attrs[(attnum)-1], \
+ fetchatt(TupleDescAttr((tupleDesc), (attnum)-1), \
(char *) (tup)->t_data + (tup)->t_data->t_hoff + \
- (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
+ TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff)\
) \
: \
nocachegetattr((tup), (attnum), (tupleDesc)) \
*(isnull) = false, \
!IndexTupleHasNulls(tup) ? \
( \
- (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
+ TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff >= 0 ? \
( \
- fetchatt((tupleDesc)->attrs[(attnum)-1], \
+ fetchatt(TupleDescAttr((tupleDesc), (attnum)-1), \
(char *) (tup) + IndexInfoFindDataOffset((tup)->t_info) \
- + (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
+ + TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff) \
) \
: \
nocache_index_getattr((tup), (attnum), (tupleDesc)) \
int tdrefcount; /* reference count, or -1 if not counting */
} *TupleDesc;
+/* Accessor for the i'th attribute of tupdesc. */
+#define TupleDescAttr(tupdesc, i) ((tupdesc)->attrs[(i)])
extern TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid);
SV *val = HeVAL(he);
char *key = hek2cstr(he);
int attn = SPI_fnumber(td, key);
+ Form_pg_attribute attr = TupleDescAttr(td, attn - 1);
if (attn == SPI_ERROR_NOATTRIBUTE)
ereport(ERROR,
key)));
values[attn - 1] = plperl_sv_to_datum(val,
- td->attrs[attn - 1]->atttypid,
- td->attrs[attn - 1]->atttypmod,
+ attr->atttypid,
+ attr->atttypmod,
NULL,
NULL,
InvalidOid,
char *key = hek2cstr(he);
SV *val = HeVAL(he);
int attn = SPI_fnumber(tupdesc, key);
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attn - 1);
if (attn == SPI_ERROR_NOATTRIBUTE)
ereport(ERROR,
key)));
modvalues[attn - 1] = plperl_sv_to_datum(val,
- tupdesc->attrs[attn - 1]->atttypid,
- tupdesc->attrs[attn - 1]->atttypmod,
+ attr->atttypid,
+ attr->atttypmod,
NULL,
NULL,
InvalidOid,
typisvarlena;
char *attname;
Oid typoutput;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
- attname = NameStr(tupdesc->attrs[i]->attname);
+ attname = NameStr(att->attname);
attr = heap_getattr(tuple, i + 1, tupdesc, &isnull);
if (isnull)
continue;
}
- if (type_is_rowtype(tupdesc->attrs[i]->atttypid))
+ if (type_is_rowtype(att->atttypid))
{
SV *sv = plperl_hash_from_datum(attr);
SV *sv;
Oid funcid;
- if (OidIsValid(get_base_element_type(tupdesc->attrs[i]->atttypid)))
- sv = plperl_ref_from_pg_array(attr, tupdesc->attrs[i]->atttypid);
- else if ((funcid = get_transform_fromsql(tupdesc->attrs[i]->atttypid, current_call_data->prodesc->lang_oid, current_call_data->prodesc->trftypes)))
+ if (OidIsValid(get_base_element_type(att->atttypid)))
+ sv = plperl_ref_from_pg_array(attr, att->atttypid);
+ else if ((funcid = get_transform_fromsql(att->atttypid, current_call_data->prodesc->lang_oid, current_call_data->prodesc->trftypes)))
sv = (SV *) DatumGetPointer(OidFunctionCall1(funcid, attr));
else
{
char *outputstr;
/* XXX should have a way to cache these lookups */
- getTypeOutputInfo(tupdesc->attrs[i]->atttypid,
- &typoutput, &typisvarlena);
+ getTypeOutputInfo(att->atttypid, &typoutput, &typisvarlena);
outputstr = OidOutputFunctionCall(typoutput, attr);
sv = cstr2sv(outputstr);
/*
* Get the attribute and check for dropped column
*/
- attrStruct = row->rowtupdesc->attrs[i];
+ attrStruct = TupleDescAttr(row->rowtupdesc, i);
if (!attrStruct->attisdropped)
{
PLpgSQL_var *var = (PLpgSQL_var *) retvar;
Datum retval = var->value;
bool isNull = var->isnull;
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, 0);
if (natts != 1)
ereport(ERROR,
&isNull,
var->datatype->typoid,
var->datatype->atttypmod,
- tupdesc->attrs[0]->atttypid,
- tupdesc->attrs[0]->atttypmod);
+ attr->atttypid,
+ attr->atttypmod);
tuplestore_putvalues(estate->tuple_store, tupdesc,
&retval, &isNull);
}
else
{
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, 0);
+
/* Simple scalar result */
if (natts != 1)
ereport(ERROR,
&isNull,
rettype,
rettypmod,
- tupdesc->attrs[0]->atttypid,
- tupdesc->attrs[0]->atttypmod);
+ attr->atttypid,
+ attr->atttypmod);
tuplestore_putvalues(estate->tuple_store, tupdesc,
&retval, &isNull);
* Now insert the new value, being careful to cast it to the
* right type.
*/
- atttype = rec->tupdesc->attrs[fno - 1]->atttypid;
- atttypmod = rec->tupdesc->attrs[fno - 1]->atttypmod;
+ atttype = TupleDescAttr(rec->tupdesc, fno - 1)->atttypid;
+ atttypmod = TupleDescAttr(rec->tupdesc, fno - 1)->atttypmod;
values[0] = exec_cast_value(estate,
value,
&isNull,
rec->refname, recfield->fieldname)));
*typeid = SPI_gettypeid(rec->tupdesc, fno);
if (fno > 0)
- *typetypmod = rec->tupdesc->attrs[fno - 1]->atttypmod;
+ {
+ Form_pg_attribute attr = TupleDescAttr(rec->tupdesc, fno - 1);
+
+ *typetypmod = attr->atttypmod;
+ }
else
*typetypmod = -1;
*value = SPI_getbinval(rec->tup, rec->tupdesc, fno, isnull);
rec->refname, recfield->fieldname)));
*typeid = SPI_gettypeid(rec->tupdesc, fno);
if (fno > 0)
- *typmod = rec->tupdesc->attrs[fno - 1]->atttypmod;
+ {
+ Form_pg_attribute attr = TupleDescAttr(rec->tupdesc, fno - 1);
+
+ *typmod = attr->atttypmod;
+ }
else
*typmod = -1;
if (fno > 0)
- *collation = rec->tupdesc->attrs[fno - 1]->attcollation;
+ {
+ Form_pg_attribute attr = TupleDescAttr(rec->tupdesc, fno - 1);
+
+ *collation = attr->attcollation;
+ }
else /* no system column types have collation */
*collation = InvalidOid;
break;
{
Datum result = 0;
int rc;
+ Form_pg_attribute attr;
/*
* If first time through, create a plan for this expression.
/*
* ... and get the column's datatype.
*/
- *rettype = estate->eval_tuptable->tupdesc->attrs[0]->atttypid;
- *rettypmod = estate->eval_tuptable->tupdesc->attrs[0]->atttypmod;
+ attr = TupleDescAttr(estate->eval_tuptable->tupdesc, 0);
+ *rettype = attr->atttypid;
+ *rettypmod = attr->atttypmod;
/*
* If there are no rows selected, the result is a NULL of that type.
var = (PLpgSQL_var *) (estate->datums[row->varnos[fnum]]);
- while (anum < td_natts && tupdesc->attrs[anum]->attisdropped)
+ while (anum < td_natts &&
+ TupleDescAttr(tupdesc, anum)->attisdropped)
anum++; /* skip dropped column in tuple */
if (anum < td_natts)
value = (Datum) 0;
isnull = true;
}
- valtype = tupdesc->attrs[anum]->atttypid;
- valtypmod = tupdesc->attrs[anum]->atttypmod;
+ valtype = TupleDescAttr(tupdesc, anum)->atttypid;
+ valtypmod = TupleDescAttr(tupdesc, anum)->atttypmod;
anum++;
}
else
Oid fieldtypeid;
int32 fieldtypmod;
- if (tupdesc->attrs[i]->attisdropped)
+ if (TupleDescAttr(tupdesc, i)->attisdropped)
{
nulls[i] = true; /* leave the column as null */
continue;
exec_eval_datum(estate, estate->datums[row->varnos[i]],
&fieldtypeid, &fieldtypmod,
&dvalues[i], &nulls[i]);
- if (fieldtypeid != tupdesc->attrs[i]->atttypid)
+ if (fieldtypeid != TupleDescAttr(tupdesc, i)->atttypid)
return NULL;
/* XXX should we insist on typmod match, too? */
}
char *plattstr;
int attn;
PLyObToDatum *att;
+ Form_pg_attribute attr;
platt = PyList_GetItem(plkeys, i);
if (PyString_Check(platt))
Py_INCREF(plval);
+ attr = TupleDescAttr(tupdesc, attn - 1);
if (plval != Py_None)
{
modvalues[attn - 1] =
(att->func) (att,
- tupdesc->attrs[attn - 1]->atttypmod,
+ attr->atttypmod,
plval,
false);
modnulls[attn - 1] = false;
InputFunctionCall(&att->typfunc,
NULL,
att->typioparam,
- tupdesc->attrs[attn - 1]->atttypmod);
+ attr->atttypmod);
modnulls[attn - 1] = true;
}
modrepls[attn - 1] = true;
list = PyList_New(ob->tupdesc->natts);
for (i = 0; i < ob->tupdesc->natts; i++)
- PyList_SET_ITEM(list, i, PyString_FromString(NameStr(ob->tupdesc->attrs[i]->attname)));
+ {
+ Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
+
+ PyList_SET_ITEM(list, i, PyString_FromString(NameStr(attr->attname)));
+ }
return list;
}
list = PyList_New(ob->tupdesc->natts);
for (i = 0; i < ob->tupdesc->natts; i++)
- PyList_SET_ITEM(list, i, PyInt_FromLong(ob->tupdesc->attrs[i]->atttypid));
+ {
+ Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
+
+ PyList_SET_ITEM(list, i, PyInt_FromLong(attr->atttypid));
+ }
return list;
}
list = PyList_New(ob->tupdesc->natts);
for (i = 0; i < ob->tupdesc->natts; i++)
- PyList_SET_ITEM(list, i, PyInt_FromLong(ob->tupdesc->attrs[i]->atttypmod));
+ {
+ Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
+
+ PyList_SET_ITEM(list, i, PyInt_FromLong(attr->atttypmod));
+ }
return list;
}
for (i = 0; i < desc->natts; i++)
{
HeapTuple typeTup;
+ Form_pg_attribute attr = TupleDescAttr(desc, i);
- if (desc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
continue;
- if (arg->in.r.atts[i].typoid == desc->attrs[i]->atttypid)
+ if (arg->in.r.atts[i].typoid == attr->atttypid)
continue; /* already set up this entry */
- typeTup = SearchSysCache1(TYPEOID,
- ObjectIdGetDatum(desc->attrs[i]->atttypid));
+ typeTup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(attr->atttypid));
if (!HeapTupleIsValid(typeTup))
elog(ERROR, "cache lookup failed for type %u",
- desc->attrs[i]->atttypid);
+ attr->atttypid);
PLy_input_datum_func2(&(arg->in.r.atts[i]), arg->mcxt,
- desc->attrs[i]->atttypid,
+ attr->atttypid,
typeTup,
exec_ctx->curr_proc->langid,
exec_ctx->curr_proc->trftypes);
for (i = 0; i < desc->natts; i++)
{
HeapTuple typeTup;
+ Form_pg_attribute attr = TupleDescAttr(desc, i);
- if (desc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
continue;
- if (arg->out.r.atts[i].typoid == desc->attrs[i]->atttypid)
+ if (arg->out.r.atts[i].typoid == attr->atttypid)
continue; /* already set up this entry */
- typeTup = SearchSysCache1(TYPEOID,
- ObjectIdGetDatum(desc->attrs[i]->atttypid));
+ typeTup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(attr->atttypid));
if (!HeapTupleIsValid(typeTup))
elog(ERROR, "cache lookup failed for type %u",
- desc->attrs[i]->atttypid);
+ attr->atttypid);
PLy_output_datum_func2(&(arg->out.r.atts[i]), arg->mcxt, typeTup,
exec_ctx->curr_proc->langid,
Datum vattr;
bool is_null;
PyObject *value;
+ Form_pg_attribute attr = TupleDescAttr(desc, i);
- if (desc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
continue;
- key = NameStr(desc->attrs[i]->attname);
+ key = NameStr(attr->attname);
vattr = heap_getattr(tuple, (i + 1), desc, &is_null);
if (is_null || info->in.r.atts[i].func == NULL)
char *key;
PyObject *volatile value;
PLyObToDatum *att;
+ Form_pg_attribute attr = TupleDescAttr(desc, i);
- if (desc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
{
values[i] = (Datum) 0;
nulls[i] = true;
continue;
}
- key = NameStr(desc->attrs[i]->attname);
+ key = NameStr(attr->attname);
value = NULL;
att = &info->out.r.atts[i];
PG_TRY();
idx = 0;
for (i = 0; i < desc->natts; i++)
{
- if (!desc->attrs[i]->attisdropped)
+ if (!TupleDescAttr(desc, i)->attisdropped)
idx++;
}
if (PySequence_Length(sequence) != idx)
PyObject *volatile value;
PLyObToDatum *att;
- if (desc->attrs[i]->attisdropped)
+ if (TupleDescAttr(desc, i)->attisdropped)
{
values[i] = (Datum) 0;
nulls[i] = true;
char *key;
PyObject *volatile value;
PLyObToDatum *att;
+ Form_pg_attribute attr = TupleDescAttr(desc, i);
- if (desc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
{
values[i] = (Datum) 0;
nulls[i] = true;
continue;
}
- key = NameStr(desc->attrs[i]->attname);
+ key = NameStr(attr->attname);
value = NULL;
att = &info->out.r.atts[i];
PG_TRY();
Tcl_ListObjAppendElement(NULL, tcl_trigtup, Tcl_NewObj());
for (i = 0; i < tupdesc->natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
+ if (att->attisdropped)
Tcl_ListObjAppendElement(NULL, tcl_trigtup, Tcl_NewObj());
else
Tcl_ListObjAppendElement(NULL, tcl_trigtup,
- Tcl_NewStringObj(utf_e2u(NameStr(tupdesc->attrs[i]->attname)), -1));
+ Tcl_NewStringObj(utf_e2u(NameStr(att->attname)), -1));
}
Tcl_ListObjAppendElement(NULL, tcl_cmd, tcl_trigtup);
for (i = 0; i < tupdesc->natts; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
/* ignore dropped attributes */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
/************************************************************
* Get the attribute name
************************************************************/
UTF_BEGIN;
- attname = pstrdup(UTF_E2U(NameStr(tupdesc->attrs[i]->attname)));
+ attname = pstrdup(UTF_E2U(NameStr(att->attname)));
UTF_END;
/************************************************************
************************************************************/
if (!isnull)
{
- getTypeOutputInfo(tupdesc->attrs[i]->atttypid,
- &typoutput, &typisvarlena);
+ getTypeOutputInfo(att->atttypid, &typoutput, &typisvarlena);
outputstr = OidOutputFunctionCall(typoutput, attr);
UTF_BEGIN;
Tcl_SetVar2Ex(interp, *arrptr, *nameptr,
for (i = 0; i < tupdesc->natts; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
/* ignore dropped attributes */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
/************************************************************
* Get the attribute name
************************************************************/
- attname = NameStr(tupdesc->attrs[i]->attname);
+ attname = NameStr(att->attname);
/************************************************************
* Get the attributes value
************************************************************/
if (!isnull)
{
- getTypeOutputInfo(tupdesc->attrs[i]->atttypid,
+ getTypeOutputInfo(att->atttypid,
&typoutput, &typisvarlena);
outputstr = OidOutputFunctionCall(typoutput, attr);
UTF_BEGIN;
struct varatt_indirect redirect_pointer;
/* only work on existing, not-null varlenas */
- if (tupdesc->attrs[i]->attisdropped ||
+ if (TupleDescAttr(tupdesc, i)->attisdropped ||
nulls[i] ||
- tupdesc->attrs[i]->attlen != -1)
+ TupleDescAttr(tupdesc, i)->attlen != -1)
continue;
attr = (struct varlena *) DatumGetPointer(values[i]);