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

Function CreateConversionCommand

src/backend/commands/conversioncmds.c:40–156  ·  view source on GitHub ↗

* CREATE CONVERSION */

Source from the content-addressed store, hash-verified

38 * CREATE CONVERSION
39 */
40ObjectAddress
41CreateConversionCommand(CreateConversionStmt *stmt)
42{
43 Oid namespaceId;
44 char *conversion_name;
45 AclResult aclresult;
46 int from_encoding;
47 int to_encoding;
48 Oid funcoid;
49 const char *from_encoding_name = stmt->for_encoding_name;
50 const char *to_encoding_name = stmt->to_encoding_name;
51 List *func_name = stmt->func_name;
52 static const Oid funcargs[] = {INT4OID, INT4OID, CSTRINGOID, INTERNALOID, INT4OID, BOOLOID};
53 char result[1];
54 Datum funcresult;
55
56 /* Convert list of names to a name and namespace */
57 namespaceId = QualifiedNameGetCreationNamespace(stmt->conversion_name,
58 &conversion_name);
59
60 /* Check we have creation rights in target namespace */
61 aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_CREATE);
62 if (aclresult != ACLCHECK_OK)
63 aclcheck_error(aclresult, OBJECT_SCHEMA,
64 get_namespace_name(namespaceId));
65
66 /* Check the encoding names */
67 from_encoding = pg_char_to_encoding(from_encoding_name);
68 if (from_encoding < 0)
69 ereport(ERROR,
70 (errcode(ERRCODE_UNDEFINED_OBJECT),
71 errmsg("source encoding \"%s\" does not exist",
72 from_encoding_name)));
73
74 to_encoding = pg_char_to_encoding(to_encoding_name);
75 if (to_encoding < 0)
76 ereport(ERROR,
77 (errcode(ERRCODE_UNDEFINED_OBJECT),
78 errmsg("destination encoding \"%s\" does not exist",
79 to_encoding_name)));
80
81 /*
82 * We consider conversions to or from SQL_ASCII to be meaningless. (If
83 * you wish to change this, note that pg_do_encoding_conversion() and its
84 * sister functions have hard-wired fast paths for any conversion in which
85 * the source or target encoding is SQL_ASCII, so that an encoding
86 * conversion function declared for such a case will never be used.)
87 */
88 if (from_encoding == PG_SQL_ASCII || to_encoding == PG_SQL_ASCII)
89 ereport(ERROR,
90 (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
91 errmsg("encoding conversion to or from \"SQL_ASCII\" is not supported")));
92
93 /*
94 * Check the existence of the conversion function. Function name could be
95 * a qualified name.
96 */
97 funcoid = LookupFuncName(func_name, sizeof(funcargs) / sizeof(Oid),

Callers 1

ProcessUtilitySlowFunction · 0.85

Calls 15

pg_namespace_aclcheckFunction · 0.85
GetUserIdFunction · 0.85
aclcheck_errorFunction · 0.85
get_namespace_nameFunction · 0.85
pg_char_to_encodingFunction · 0.85
LookupFuncNameFunction · 0.85
get_func_rettypeFunction · 0.85
NameListToStringFunction · 0.85
pg_proc_aclcheckFunction · 0.85
Int32GetDatumFunction · 0.85
CStringGetDatumFunction · 0.85

Tested by

no test coverage detected