mirror of
https://github.com/postgres/postgres.git
synced 2025-08-02 09:26:47 +03:00
Add SQL-callable pg_get_object_address
This allows access to get_object_address from SQL, which is useful to obtain OID addressing information from data equivalent to that emitted by the parser. This is necessary infrastructure of a project to let replication systems propagate object dropping events to remote servers, where the schema might be different than the server originating the DROP. This patch also adds support for OBJECT_DEFAULT to get_object_address; that is, it is now possible to refer to a column's default value. Catalog version bumped due to the new function. Reviewed by Stephen Frost, Heikki Linnakangas, Robert Haas, Andres Freund, Abhijit Menon-Sen, Adam Brightwell.
This commit is contained in:
src
backend
include
test
regress
@ -705,13 +705,11 @@ pts_error_callback(void *arg)
|
||||
/*
|
||||
* 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.
|
||||
* the string and return the result as a TypeName.
|
||||
* If the string cannot be parsed as a type, an error is raised.
|
||||
*/
|
||||
void
|
||||
parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p,
|
||||
bool missing_ok)
|
||||
TypeName *
|
||||
typeStringToTypeName(const char *str)
|
||||
{
|
||||
StringInfoData buf;
|
||||
List *raw_parsetree_list;
|
||||
@ -720,7 +718,6 @@ parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p,
|
||||
TypeCast *typecast;
|
||||
TypeName *typeName;
|
||||
ErrorContextCallback ptserrcontext;
|
||||
Type tup;
|
||||
|
||||
/* make sure we give useful error for empty input */
|
||||
if (strspn(str, " \t\n\r\f") == strlen(str))
|
||||
@ -779,6 +776,7 @@ parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p,
|
||||
typecast->arg == NULL ||
|
||||
!IsA(typecast->arg, A_Const))
|
||||
goto fail;
|
||||
|
||||
typeName = typecast->typeName;
|
||||
if (typeName == NULL ||
|
||||
!IsA(typeName, TypeName))
|
||||
@ -786,6 +784,31 @@ parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p,
|
||||
if (typeName->setof)
|
||||
goto fail;
|
||||
|
||||
pfree(buf.data);
|
||||
|
||||
return typeName;
|
||||
|
||||
fail:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("invalid type name \"%s\"", str)));
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
void
|
||||
parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
|
||||
{
|
||||
TypeName *typeName;
|
||||
Type tup;
|
||||
|
||||
typeName = typeStringToTypeName(str);
|
||||
|
||||
tup = LookupTypeName(NULL, typeName, typmod_p, missing_ok);
|
||||
if (tup == NULL)
|
||||
{
|
||||
@ -808,13 +831,4 @@ parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p,
|
||||
*typeid_p = HeapTupleGetOid(tup);
|
||||
ReleaseSysCache(tup);
|
||||
}
|
||||
|
||||
pfree(buf.data);
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("invalid type name \"%s\"", str)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user