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

Function lookup_object_oid

src/bin/psql/command.c:5047–5101  ·  view source on GitHub ↗

* Look up the object identified by obj_type and desc. If successful, * store its OID in *obj_oid and return true, else return false. * * Note that we'll fail if the object doesn't exist OR if there are multiple * matching candidates OR if there's something syntactically wrong with the * object description; unfortunately it can be hard to tell the difference. */

Source from the content-addressed store, hash-verified

5045 * object description; unfortunately it can be hard to tell the difference.
5046 */
5047static bool
5048lookup_object_oid(EditableObjectType obj_type, const char *desc,
5049 Oid *obj_oid)
5050{
5051 bool result = true;
5052 PQExpBuffer query = createPQExpBuffer();
5053 PGresult *res;
5054
5055 switch (obj_type)
5056 {
5057 case EditableFunction:
5058
5059 /*
5060 * We have a function description, e.g. "x" or "x(int)". Issue a
5061 * query to retrieve the function's OID using a cast to regproc or
5062 * regprocedure (as appropriate).
5063 */
5064 appendPQExpBufferStr(query, "SELECT ");
5065 appendStringLiteralConn(query, desc, pset.db);
5066 appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
5067 strchr(desc, '(') ? "regprocedure" : "regproc");
5068 break;
5069
5070 case EditableView:
5071
5072 /*
5073 * Convert view name (possibly schema-qualified) to OID. Note:
5074 * this code doesn't check if the relation is actually a view.
5075 * We'll detect that in get_create_object_cmd().
5076 */
5077 appendPQExpBufferStr(query, "SELECT ");
5078 appendStringLiteralConn(query, desc, pset.db);
5079 appendPQExpBufferStr(query, "::pg_catalog.regclass::pg_catalog.oid");
5080 break;
5081 }
5082
5083 if (!echo_hidden_command(query->data))
5084 {
5085 destroyPQExpBuffer(query);
5086 return false;
5087 }
5088 res = PQexec(pset.db, query->data);
5089 if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
5090 *obj_oid = atooid(PQgetvalue(res, 0, 0));
5091 else
5092 {
5093 minimal_error_message(res);
5094 result = false;
5095 }
5096
5097 PQclear(res);
5098 destroyPQExpBuffer(query);
5099
5100 return result;
5101}
5102
5103/*
5104 * Construct a "CREATE OR REPLACE ..." command that describes the specified

Callers 2

exec_command_ef_evFunction · 0.85
exec_command_sf_svFunction · 0.85

Calls 12

createPQExpBufferFunction · 0.85
appendPQExpBufferStrFunction · 0.85
appendStringLiteralConnFunction · 0.85
appendPQExpBufferFunction · 0.85
echo_hidden_commandFunction · 0.85
destroyPQExpBufferFunction · 0.85
PQexecFunction · 0.85
PQresultStatusFunction · 0.85
PQntuplesFunction · 0.85
PQgetvalueFunction · 0.85
minimal_error_messageFunction · 0.85
PQclearFunction · 0.85

Tested by

no test coverage detected