summaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorAlvaro Herrera2014-12-23 18:31:29 +0000
committerAlvaro Herrera2014-12-23 18:31:29 +0000
commitd7ee82e50f624221db76023c17137661fe69ec61 (patch)
treef216334b5fa69a671f68e2442a3b602472ec7135 /src/backend/parser
parent1826987a46d079458007b7b6bbcbbd852353adbb (diff)
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.
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/parse_type.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c
index d0803dfafd1..299cc5359ff 100644
--- a/src/backend/parser/parse_type.c
+++ b/src/backend/parser/parse_type.c
@@ -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)));
}