PostgreSQL Source Code: src/backend/parser/parse_type.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16

28

31

32

33

34

35

36

39 int32 *typmod_p, bool missing_ok)

40{

42 typeName, typmod_p, true, missing_ok);

43}

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

75 bool temp_ok, bool missing_ok)

76{

77 Oid typoid;

80

82 {

83

84 typoid = typeName->typeOid;

85 }

87 {

88

90 char *field = NULL;

91 Oid relid;

93

94

96 {

97 case 1:

99 (errcode(ERRCODE_SYNTAX_ERROR),

100 errmsg("improper %%TYPE reference (too few dotted names): %s",

103 break;

104 case 2:

107 break;

108 case 3:

112 break;

113 case 4:

118 break;

119 default:

121 (errcode(ERRCODE_SYNTAX_ERROR),

122 errmsg("improper %%TYPE reference (too many dotted names): %s",

125 break;

126 }

127

128

129

130

131

132

133

134

138 {

139 if (missing_ok)

141 else

143 (errcode(ERRCODE_UNDEFINED_COLUMN),

144 errmsg("column \"%s\" of relation \"%s\" does not exist",

147 }

148 else

149 {

151

152

154

155

157 (errmsg("type reference %s converted to %s",

160 }

161 }

162 else

163 {

164

165 char *schemaname;

167

168

170

171 if (schemaname)

172 {

173

174 Oid namespaceId;

176

178

184 else

186

188 }

189 else

190 {

191

193 }

194

195

198 }

199

201 {

202 if (typmod_p)

203 *typmod_p = -1;

204 return NULL;

205 }

206

209 elog(ERROR, "cache lookup failed for type %u", typoid);

210

212

213 if (typmod_p)

214 *typmod_p = typmod;

215

216 return (Type) tup;

217}

218

219

220

221

222

223

224

225

226

227

228

229

230

233{

234 Oid typoid;

236

237 tup = LookupTypeName(pstate, typeName, NULL, missing_ok);

238 if (tup == NULL)

239 {

240 if (!missing_ok)

242 (errcode(ERRCODE_UNDEFINED_OBJECT),

243 errmsg("type \"%s\" does not exist",

246

248 }

249

252

253 return typoid;

254}

255

256

257

258

259

260

261

262

265{

267

268 tup = LookupTypeName(pstate, typeName, typmod_p, false);

269 if (tup == NULL)

271 (errcode(ERRCODE_UNDEFINED_OBJECT),

272 errmsg("type \"%s\" does not exist",

277 (errcode(ERRCODE_UNDEFINED_OBJECT),

278 errmsg("type \"%s\" is only a shell",

281 return tup;

282}

283

284

285

286

287

288

289

292{

293 Oid typoid;

295

299

300 return typoid;

301}

302

303

304

305

306

307

308

309void

311 Oid *typeid_p, int32 *typmod_p)

312{

314

315 tup = typenameType(pstate, typeName, typmod_p);

318}

319

320

321

322

323

324

325

326

327

328

329

330

333{

335 Oid typmodin;

337 int n;

341

342

344 return typeName->typemod;

345

346

347

348

349

350

353 (errcode(ERRCODE_SYNTAX_ERROR),

354 errmsg("type modifier cannot be specified for shell type \"%s\"",

357

359

362 (errcode(ERRCODE_SYNTAX_ERROR),

363 errmsg("type modifier is not allowed for type \"%s\"",

366

367

368

369

370

371

373 n = 0;

374 foreach(l, typeName->typmods)

375 {

377 char *cstr = NULL;

378

380 {

382

384 {

386 }

388 {

389

391 }

393 {

394

396 }

397 }

399 {

401

405 }

406 if (!cstr)

408 (errcode(ERRCODE_SYNTAX_ERROR),

409 errmsg("type modifiers must be simple constants or identifiers"),

412 }

413

415

416

418

421

423

425 pfree(arrtypmod);

426

427 return result;

428}

429

430

431

432

433

434

435

436

437

438static void

440{

442 {

443

445

446 foreach(l, typeName->names)

447 {

451 }

452 }

453 else

454 {

455

457 }

458

459

460

461

462

465

468}

469

470

471

472

473

474

475

476

477char *

479{

481

484 return string.data;

485}

486

487

488

489

490

491char *

493{

496

499 {

501

505 }

506 return string.data;

507}

508

509

510

511

512

513

516{

517 Oid colloid;

519

520 if (pstate)

522

524

525 if (pstate)

527

528 return colloid;

529}

530

531

532

533

534

535

536

537

538

541{

542 Oid result;

544 int location = coldef->location;

545

547 {

548

551 location);

552 }

554 {

555

556 result = coldef->collOid;

557 }

558 else

559 {

560

561 result = typcollation;

562 }

563

564

567 (errcode(ERRCODE_DATATYPE_MISMATCH),

568 errmsg("collations are not supported by type %s",

571

572 return result;

573}

574

575

576

579{

581

584 elog(ERROR, "cache lookup failed for type %u", id);

585 return (Type) tup;

586}

587

588

591{

592 if (tp == NULL)

593 elog(ERROR, "typeTypeId() called with NULL type struct");

595}

596

597

600{

602

604 return typ->typlen;

605}

606

607

608bool

610{

612

614 return typ->typbyval;

615}

616

617

618char *

620{

622

624

626}

627

628

631{

633

635 return typtup->typrelid;

636}

637

638

641{

643

645 return typtup->typcollation;

646}

647

648

649

650

651

652

655{

657 Oid typinput = typform->typinput;

659

661}

662

663

664

665

666

669{

672 Oid result;

673

676 elog(ERROR, "cache lookup failed for type %u", type_id);

678 result = type->typrelid;

680 return result;

681}

682

683

684

685

686

687

690{

693 Oid result;

694

695 for (;;)

696 {

699 elog(ERROR, "cache lookup failed for type %u", type_id);

701 if (type->typtype != TYPTYPE_DOMAIN)

702 {

703

704 break;

705 }

706

707 type_id = type->typbasetype;

709 }

710 result = type->typrelid;

712 return result;

713}

714

715

716

717

718static void

720{

721 const char *str = (const char *) arg;

722

724}

725

726

727

728

729

730

731

732

733

734

735

736

739{

740 List *raw_parsetree_list;

743

744

745 if (strspn(str, " \t\n\r\f\v") == strlen(str))

746 goto fail;

747

748

749

750

755

757

759

760

763

764

765 if (typeName->setof)

766 goto fail;

767

768 return typeName;

769

770fail:

772 (errcode(ERRCODE_SYNTAX_ERROR),

773 errmsg("invalid type name \"%s\"", str)));

774}

775

776

777

778

779

780

781

782

783

784bool

786 Node *escontext)

787{

790

792 if (typeName == NULL)

793 return false;

794

797 if (tup == NULL)

798 {

799 ereturn(escontext, false,

800 (errcode(ERRCODE_UNDEFINED_OBJECT),

801 errmsg("type \"%s\" does not exist",

803 }

804 else

805 {

807

808 if (!typ->typisdefined)

809 {

811 ereturn(escontext, false,

812 (errcode(ERRCODE_UNDEFINED_OBJECT),

813 errmsg("type \"%s\" is only a shell",

815 }

816 *typeid_p = typ->oid;

818 }

819

820 return true;

821}

ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)

#define InvalidAttrNumber

List * raw_parser(const char *str, RawParseMode mode)

#define unconstify(underlying_type, expr)

#define OidIsValid(objectId)

ErrorContextCallback * error_context_stack

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereturn(context, dummy_value,...)

#define ereport(elevel,...)

#define palloc_array(type, count)

Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)

#define OidFunctionCall1(functionId, arg1)

char * format_type_be(Oid type_oid)

Assert(PointerIsAligned(start, uint64))

#define HeapTupleIsValid(tuple)

static void * GETSTRUCT(const HeapTupleData *tuple)

AttrNumber get_attnum(Oid relid, const char *attname)

Oid get_typcollation(Oid typid)

Oid getTypeIOParam(HeapTuple typeTuple)

Oid get_array_type(Oid typid)

Oid get_atttype(Oid relid, AttrNumber attnum)

RangeVar * makeRangeVar(char *schemaname, char *relname, int location)

char * pstrdup(const char *in)

void pfree(void *pointer)

char * NameListToString(const List *names)

Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)

Oid get_collation_oid(List *collname, bool missing_ok)

void DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p)

Oid TypenameGetTypidExtended(const char *typname, bool temp_ok)

#define RangeVarGetRelid(relation, lockmode, missing_ok)

#define IsA(nodeptr, _type_)

void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)

int parser_errposition(ParseState *pstate, int location)

void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)

static void appendTypeNameToBuffer(const TypeName *typeName, StringInfo string)

Oid typeTypeRelid(Type typ)

Oid typeOrDomainTypeRelid(Oid type_id)

Oid LookupCollation(ParseState *pstate, List *collnames, int location)

Type LookupTypeNameExtended(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool temp_ok, bool missing_ok)

char * TypeNameToString(const TypeName *typeName)

Oid typeTypeCollation(Type typ)

void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)

bool parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, Node *escontext)

Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)

Oid typeidTypeRelid(Oid type_id)

char * typeTypeName(Type t)

static void pts_error_callback(void *arg)

Datum stringTypeDatum(Type tp, char *string, int32 atttypmod)

Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)

static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)

char * TypeNameListToString(List *typenames)

TypeName * typeStringToTypeName(const char *str, Node *escontext)

Oid GetColumnDefCollation(ParseState *pstate, const ColumnDef *coldef, Oid typeOid)

Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)

Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)

#define lfirst_node(type, lc)

static int list_length(const List *l)

#define linitial_node(type, l)

static ListCell * list_head(const List *l)

FormData_pg_type * Form_pg_type

static Datum PointerGetDatum(const void *X)

static Datum ObjectIdGetDatum(Oid X)

static Datum CStringGetDatum(const char *X)

static int32 DatumGetInt32(Datum X)

char * psprintf(const char *fmt,...)

void appendStringInfoString(StringInfo str, const char *s)

void appendStringInfoChar(StringInfo str, char ch)

void initStringInfo(StringInfo str)

CollateClause * collClause

struct ErrorContextCallback * previous

void(* callback)(void *arg)

void ReleaseSysCache(HeapTuple tuple)

HeapTuple SearchSysCache1(int cacheId, Datum key1)

#define GetSysCacheOid2(cacheId, oidcol, key1, key2)