src/bin/psql/command.c
static bool
lookup_object_oid(EditableObjectType obj_type, const char *desc,
				  Oid *obj_oid)
{
	bool		result = true;
	PQExpBuffer query = createPQExpBuffer();
	PGresult   *res;

	switch (obj_type)
	{
		case EditableFunction:

			/*
			 * We have a function description, e.g. "x" or "x(int)".  Issue a
			 * query to retrieve the function's OID using a cast to regproc or
			 * regprocedure (as appropriate).
			 */
			appendPQExpBufferStr(query, "SELECT ");
			appendStringLiteralConn(query, desc, pset.db);
			appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
							  strchr(desc, '(') ? "regprocedure" : "regproc");
			break;

		case EditableView:

			/*
			 * Convert view name (possibly schema-qualified) to OID.  Note:
			 * this code doesn't check if the relation is actually a view.
			 * We'll detect that in get_create_object_cmd().
			 */
			appendPQExpBufferStr(query, "SELECT ");
			appendStringLiteralConn(query, desc, pset.db);
			appendPQExpBufferStr(query, "::pg_catalog.regclass::pg_catalog.oid");
			break;
	}

	if (!echo_hidden_command(query->data))
	{
		destroyPQExpBuffer(query);
		return false;
	}
	res = PQexec(pset.db, query->data);
	if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
		*obj_oid = atooid(PQgetvalue(res, 0, 0));
	else
	{
		minimal_error_message(res);
		result = false;
	}

	PQclear(res);
	destroyPQExpBuffer(query);

	return result;
}
/*
 * 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.
 */
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.
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 .
static bool
lookup_object_oid(EditableObjectType obj_type, const char *desc,
				  Oid *obj_oid)
{
	bool		result = true;
	PQExpBuffer query = createPQExpBuffer();
	PGresult   *res;
	switch (obj_type)
	{
		case EditableFunction:
			appendPQExpBufferStr(query, "SELECT ");
			appendStringLiteralConn(query, desc, pset.db);
			appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
							  strchr(desc, '(') ? "regprocedure" : "regproc");
			break;
		case EditableView:
			appendPQExpBufferStr(query, "SELECT ");
			appendStringLiteralConn(query, desc, pset.db);
			appendPQExpBufferStr(query, "::pg_catalog.regclass::pg_catalog.oid");
			break;
	}
	if (!echo_hidden_command(query->data))
	{
		destroyPQExpBuffer(query);
		return false;
	}
	res = PQexec(pset.db, query->data);
	if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
		*obj_oid = atooid(PQgetvalue(res, 0, 0));
	else
	{
		minimal_error_message(res);
		result = false;
	}
	PQclear(res);
	destroyPQExpBuffer(query);
	return result;
}
static bool lookup_object_oid ( EditableObjectType obj_type , const char * desc , Oid * obj_oid ) { bool result = true ; PQExpBuffer query = createPQExpBuffer ( ) ; PGresult * res ; switch ( obj_type ) { case EditableFunction : appendPQExpBufferStr ( query , " " ) ; appendStringLiteralConn ( query , desc , pset . db ) ; appendPQExpBuffer ( query , " " , strchr ( desc , ' ' ) ? " " : " " ) ; break ; case EditableView : appendPQExpBufferStr ( query , " " ) ; appendStringLiteralConn ( query , desc , pset . db ) ; appendPQExpBufferStr ( query , " " ) ; break ; } if ( ! echo_hidden_command ( query -> data ) ) { destroyPQExpBuffer ( query ) ; return false ; } res = PQexec ( pset . db , query -> data ) ; if ( PQresultStatus ( res ) == PGRES_TUPLES_OK && PQntuples ( res ) == 1 ) * obj_oid = atooid ( PQgetvalue ( res , 0 , 0 ) ) ; else { minimal_error_message ( res ) ; result = false ; } PQclear ( res ) ; destroyPQExpBuffer ( query ) ; return result ; }
Look up the object identified by obj_type and desc.
Look up the object identified by obj_type and desc .
/*
			 * We have a function description, e.g. "x" or "x(int)".  Issue a
			 * query to retrieve the function's OID using a cast to regproc or
			 * regprocedure (as appropriate).
			 */ /*
			 * Convert view name (possibly schema-qualified) to OID.  Note:
			 * this code doesn't check if the relation is actually a view.
			 * We'll detect that in get_create_object_cmd().
			 */