Update CopyGetAttnums with latest from PostgreSQL

This function was recently modified to use the TupleDescAttr wrapper,
which abstracts away recent changes to TupleDesc.
pull/1633/head
Jason Petersen 2017-08-31 16:04:56 -06:00
parent 91d9b41822
commit 6a020b5adc
No known key found for this signature in database
GPG Key ID: 9F1D3510D110ABA9
1 changed files with 8 additions and 17 deletions

View File

@ -3257,16 +3257,13 @@ CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
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);
}
}
@ -3285,41 +3282,35 @@ CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
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;
}
}
if (attnum == InvalidAttrNumber)
{
if (rel != NULL)
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" of relation \"%s\" does not exist",
name, RelationGetRelationName(rel))));
}
errmsg("column \"%s\" of relation \"%s\" does not exist",
name, RelationGetRelationName(rel))));
else
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" does not exist",
name)));
}
}
/* Check for duplicates */
if (list_member_int(attnums, attnum))
{
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_COLUMN),
errmsg("column \"%s\" specified more than once",
name)));
}
attnums = lappend_int(attnums, attnum);
}
}