* Given a string that is supposed to be a SQL-compatible type declaration, * such as "int4" or "integer" or "character varying(32)", parse * the string and convert it to a type OID and type modifier. * If missing_ok is true, InvalidOid is returned rather than raising an error * when the type name is not found. */
| 777 | * when the type name is not found. |
| 778 | */ |
| 779 | void |
| 780 | parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok) |
| 781 | { |
| 782 | TypeName *typeName; |
| 783 | Type tup; |
| 784 | |
| 785 | typeName = typeStringToTypeName(str); |
| 786 | |
| 787 | tup = LookupTypeName(NULL, typeName, typmod_p, missing_ok); |
| 788 | if (tup == NULL) |
| 789 | { |
| 790 | if (!missing_ok) |
| 791 | ereport(ERROR, |
| 792 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 793 | errmsg("type \"%s\" does not exist", |
| 794 | TypeNameToString(typeName)), |
| 795 | parser_errposition(NULL, typeName->location))); |
| 796 | *typeid_p = InvalidOid; |
| 797 | } |
| 798 | else |
| 799 | { |
| 800 | Form_pg_type typ = (Form_pg_type) GETSTRUCT(tup); |
| 801 | |
| 802 | if (!typ->typisdefined) |
| 803 | ereport(ERROR, |
| 804 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 805 | errmsg("type \"%s\" is only a shell", |
| 806 | TypeNameToString(typeName)), |
| 807 | parser_errposition(NULL, typeName->location))); |
| 808 | *typeid_p = typ->oid; |
| 809 | ReleaseSysCache(tup); |
| 810 | } |
| 811 | } |
no test coverage detected