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

Function typeStringToTypeName

src/backend/parser/parse_type.c:732–770  ·  view source on GitHub ↗

* 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 return the result as a TypeName. * If the string cannot be parsed as a type, an error is raised. */

Source from the content-addressed store, hash-verified

730 * If the string cannot be parsed as a type, an error is raised.
731 */
732TypeName *
733typeStringToTypeName(const char *str)
734{
735 List *raw_parsetree_list;
736 TypeName *typeName;
737 ErrorContextCallback ptserrcontext;
738
739 /* make sure we give useful error for empty input */
740 if (strspn(str, " \t\n\r\f") == strlen(str))
741 goto fail;
742
743 /*
744 * Setup error traceback support in case of ereport() during parse
745 */
746 ptserrcontext.callback = pts_error_callback;
747 ptserrcontext.arg = unconstify(char *, str);
748 ptserrcontext.previous = error_context_stack;
749 error_context_stack = &ptserrcontext;
750
751 raw_parsetree_list = raw_parser(str, RAW_PARSE_TYPE_NAME);
752
753 error_context_stack = ptserrcontext.previous;
754
755 /* We should get back exactly one TypeName node. */
756 Assert(list_length(raw_parsetree_list) == 1);
757 typeName = linitial_node(TypeName, raw_parsetree_list);
758
759 /* The grammar allows SETOF in TypeName, but we don't want that here. */
760 if (typeName->setof)
761 goto fail;
762
763 return typeName;
764
765fail:
766 ereport(ERROR,
767 (errcode(ERRCODE_SYNTAX_ERROR),
768 errmsg("invalid type name \"%s\"", str)));
769 return NULL; /* keep compiler quiet */
770}
771
772/*
773 * Given a string that is supposed to be a SQL-compatible type declaration,

Callers 2

parseTypeStringFunction · 0.85
pg_get_object_addressFunction · 0.85

Calls 4

raw_parserFunction · 0.85
list_lengthFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected