MCPcopy Create free account
hub / github.com/apache/cloudberry / GetColumnDefCollation

Function GetColumnDefCollation

src/backend/parser/parse_type.c:539–573  ·  view source on GitHub ↗

* GetColumnDefCollation * * Get the collation to be used for a column being defined, given the * ColumnDef node and the previously-determined column type OID. * * pstate is only used for error location purposes, and can be NULL. */

Source from the content-addressed store, hash-verified

537 * pstate is only used for error location purposes, and can be NULL.
538 */
539Oid
540GetColumnDefCollation(ParseState *pstate, ColumnDef *coldef, Oid typeOid)
541{
542 Oid result;
543 Oid typcollation = get_typcollation(typeOid);
544 int location = coldef->location;
545
546 if (coldef->collClause)
547 {
548 /* We have a raw COLLATE clause, so look up the collation */
549 location = coldef->collClause->location;
550 result = LookupCollation(pstate, coldef->collClause->collname,
551 location);
552 }
553 else if (OidIsValid(coldef->collOid))
554 {
555 /* Precooked collation spec, use that */
556 result = coldef->collOid;
557 }
558 else
559 {
560 /* Use the type's default collation if any */
561 result = typcollation;
562 }
563
564 /* Complain if COLLATE is applied to an uncollatable type */
565 if (OidIsValid(result) && !OidIsValid(typcollation))
566 ereport(ERROR,
567 (errcode(ERRCODE_DATATYPE_MISMATCH),
568 errmsg("collations are not supported by type %s",
569 format_type_be(typeOid)),
570 parser_errposition(pstate, location)));
571
572 return result;
573}
574
575/* return a Type structure, given a type id */
576/* NB: caller must ReleaseSysCache the type tuple when done with it */

Callers 6

MergeAttributesFunction · 0.85
ATExecAddColumnFunction · 0.85
ATPrepAlterColumnTypeFunction · 0.85
ATExecAlterColumnTypeFunction · 0.85
BuildDescForRelationFunction · 0.85

Calls 6

get_typcollationFunction · 0.85
LookupCollationFunction · 0.85
format_type_beFunction · 0.85
parser_errpositionFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected