* 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. */
| 537 | * pstate is only used for error location purposes, and can be NULL. |
| 538 | */ |
| 539 | Oid |
| 540 | GetColumnDefCollation(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 */ |
no test coverage detected