* TupleDescInitEntry * This function initializes a single attribute structure in * a previously allocated tuple descriptor. * * If attributeName is NULL, the attname field is set to an empty string * (this is for cases where we don't know or need a name for the field). * Also, some callers use this function to change the datatype-related fields * in an existing tupdesc; they pass attribut
| 588 | * TupleDescInitEntryCollation. |
| 589 | */ |
| 590 | void |
| 591 | TupleDescInitEntry(TupleDesc desc, |
| 592 | AttrNumber attributeNumber, |
| 593 | const char *attributeName, |
| 594 | Oid oidtypeid, |
| 595 | int32 typmod, |
| 596 | int attdim) |
| 597 | { |
| 598 | HeapTuple tuple; |
| 599 | Form_pg_type typeForm; |
| 600 | Form_pg_attribute att; |
| 601 | |
| 602 | /* |
| 603 | * sanity checks |
| 604 | */ |
| 605 | AssertArg(PointerIsValid(desc)); |
| 606 | AssertArg(attributeNumber >= 1); |
| 607 | AssertArg(attributeNumber <= desc->natts); |
| 608 | |
| 609 | /* |
| 610 | * initialize the attribute fields |
| 611 | */ |
| 612 | att = TupleDescAttr(desc, attributeNumber - 1); |
| 613 | |
| 614 | att->attrelid = 0; /* dummy value */ |
| 615 | |
| 616 | /* |
| 617 | * Note: attributeName can be NULL, because the planner doesn't always |
| 618 | * fill in valid resname values in targetlists, particularly for resjunk |
| 619 | * attributes. Also, do nothing if caller wants to re-use the old attname. |
| 620 | */ |
| 621 | if (attributeName == NULL) |
| 622 | MemSet(NameStr(att->attname), 0, NAMEDATALEN); |
| 623 | else if (attributeName != NameStr(att->attname)) |
| 624 | namestrcpy(&(att->attname), attributeName); |
| 625 | |
| 626 | att->attstattarget = -1; |
| 627 | att->attcacheoff = -1; |
| 628 | att->atttypmod = typmod; |
| 629 | |
| 630 | att->attnum = attributeNumber; |
| 631 | att->attndims = attdim; |
| 632 | |
| 633 | att->attnotnull = false; |
| 634 | att->atthasdef = false; |
| 635 | att->atthasmissing = false; |
| 636 | att->attidentity = '\0'; |
| 637 | att->attgenerated = '\0'; |
| 638 | att->attisdropped = false; |
| 639 | att->attislocal = true; |
| 640 | att->attinhcount = 0; |
| 641 | /* attacl, attoptions and attfdwoptions are not present in tupledescs */ |
| 642 | |
| 643 | tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(oidtypeid)); |
| 644 | if (!HeapTupleIsValid(tuple)) |
| 645 | elog(ERROR, "cache lookup failed for type %u", oidtypeid); |
| 646 | typeForm = (Form_pg_type) GETSTRUCT(tuple); |
| 647 |