From: Alvaro Herrera Date: Sun, 21 Jun 2015 19:08:49 +0000 (-0300) Subject: Add transforms to pg_get_object_address and friends X-Git-Tag: REL9_5_ALPHA1~43 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad89a5d115;p=postgresql Add transforms to pg_get_object_address and friends This was missed when transforms were added by commit cac76582053ef8e. Extracted from a larger patch Author: Michael Paquier --- diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index c37e38fa3b..83390f6bab 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -634,6 +634,10 @@ static const struct object_type_map /* OCLASS_POLICY */ { "policy", OBJECT_POLICY + }, + /* OCLASS_TRANSFORM */ + { + "transform", OBJECT_TRANSFORM } }; @@ -1855,7 +1859,7 @@ pg_get_object_address(PG_FUNCTION_ARGS) * exceptions. */ if (type == OBJECT_TYPE || type == OBJECT_DOMAIN || type == OBJECT_CAST || - type == OBJECT_DOMCONSTRAINT) + type == OBJECT_TRANSFORM || type == OBJECT_DOMCONSTRAINT) { Datum *elems; bool *nulls; @@ -1946,6 +1950,7 @@ pg_get_object_address(PG_FUNCTION_ARGS) case OBJECT_CAST: case OBJECT_USER_MAPPING: case OBJECT_DEFACL: + case OBJECT_TRANSFORM: if (list_length(args) != 1) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), @@ -3599,6 +3604,10 @@ getObjectTypeDescription(const ObjectAddress *object) appendStringInfoString(&buffer, "policy"); break; + case OCLASS_TRANSFORM: + appendStringInfoString(&buffer, "transform"); + break; + default: appendStringInfo(&buffer, "unrecognized %u", object->classId); break; @@ -4521,6 +4530,40 @@ getObjectIdentityParts(const ObjectAddress *object, break; } + case OCLASS_TRANSFORM: + { + Relation transformDesc; + HeapTuple tup; + Form_pg_transform transform; + char *transformLang; + char *transformType; + + transformDesc = heap_open(TransformRelationId, AccessShareLock); + + tup = get_catalog_object_by_oid(transformDesc, object->objectId); + + if (!HeapTupleIsValid(tup)) + elog(ERROR, "could not find tuple for transform %u", + object->objectId); + + transform = (Form_pg_transform) GETSTRUCT(tup); + + transformType = format_type_be_qualified(transform->trftype); + transformLang = get_language_name(transform->trflang, false); + + appendStringInfo(&buffer, "for %s on language %s", + transformType, + transformLang); + if (objname) + { + *objname = list_make1(transformType); + *objargs = list_make1(pstrdup(transformLang)); + } + + heap_close(transformDesc, AccessShareLock); + } + break; + default: appendStringInfo(&buffer, "unrecognized object %u %u %d", object->classId, diff --git a/src/test/regress/expected/object_address.out b/src/test/regress/expected/object_address.out index 365dcca718..034c0b1271 100644 --- a/src/test/regress/expected/object_address.out +++ b/src/test/regress/expected/object_address.out @@ -32,6 +32,9 @@ CREATE SERVER "integer" FOREIGN DATA WRAPPER addr_fdw; CREATE USER MAPPING FOR regtest_addr_user SERVER "integer"; ALTER DEFAULT PRIVILEGES FOR ROLE regtest_addr_user IN SCHEMA public GRANT ALL ON TABLES TO regtest_addr_user; ALTER DEFAULT PRIVILEGES FOR ROLE regtest_addr_user REVOKE DELETE ON TABLES FROM regtest_addr_user; +CREATE TRANSFORM FOR int LANGUAGE SQL ( + FROM SQL WITH FUNCTION varchar_transform(internal), + TO SQL WITH FUNCTION int4recv(internal)); -- test some error cases SELECT pg_get_object_address('stone', '{}', '{}'); ERROR: unrecognized object type "stone" @@ -76,7 +79,7 @@ BEGIN ('operator'), ('operator class'), ('operator family'), ('rule'), ('trigger'), ('text search parser'), ('text search dictionary'), ('text search template'), ('text search configuration'), - ('policy'), ('user mapping'), ('default acl'), + ('policy'), ('user mapping'), ('default acl'), ('transform'), ('operator of access method'), ('function of access method') LOOP FOR names IN VALUES ('{eins}'), ('{addr_nsp, zwei}'), ('{eins, zwei, drei}') @@ -261,6 +264,12 @@ WARNING: error for default acl,{addr_nsp,zwei},{}: argument list length must be WARNING: error for default acl,{addr_nsp,zwei},{integer}: unrecognized default ACL object type i WARNING: error for default acl,{eins,zwei,drei},{}: argument list length must be exactly 1 WARNING: error for default acl,{eins,zwei,drei},{integer}: unrecognized default ACL object type i +WARNING: error for transform,{eins},{}: argument list length must be exactly 1 +WARNING: error for transform,{eins},{integer}: type "eins" does not exist +WARNING: error for transform,{addr_nsp,zwei},{}: name list length must be exactly 1 +WARNING: error for transform,{addr_nsp,zwei},{integer}: name list length must be exactly 1 +WARNING: error for transform,{eins,zwei,drei},{}: name list length must be exactly 1 +WARNING: error for transform,{eins,zwei,drei},{integer}: name list length must be exactly 1 WARNING: error for operator of access method,{eins},{}: name list length must be at least 3 WARNING: error for operator of access method,{eins},{integer}: name list length must be at least 3 WARNING: error for operator of access method,{addr_nsp,zwei},{}: name list length must be at least 3 @@ -363,7 +372,8 @@ WITH objects (type, name, args) AS (VALUES ('default acl', '{regtest_addr_user}', '{r}'), -- extension -- event trigger - ('policy', '{addr_nsp, gentable, genpol}', '{}') + ('policy', '{addr_nsp, gentable, genpol}', '{}'), + ('transform', '{int}', '{sql}') ) SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.subobjid)).*, -- test roundtrip through pg_identify_object_as_address @@ -411,11 +421,12 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.subobjid)).*, operator family | pg_catalog | integer_ops | pg_catalog.integer_ops USING btree | t policy | | | genpol on addr_nsp.gentable | t collation | pg_catalog | "default" | pg_catalog."default" | t + transform | | | for integer on language sql | t text search dictionary | addr_nsp | addr_ts_dict | addr_nsp.addr_ts_dict | t text search parser | addr_nsp | addr_ts_prs | addr_nsp.addr_ts_prs | t text search configuration | addr_nsp | addr_ts_conf | addr_nsp.addr_ts_conf | t text search template | addr_nsp | addr_ts_temp | addr_nsp.addr_ts_temp | t -(40 rows) +(41 rows) --- --- Cleanup resources diff --git a/src/test/regress/sql/object_address.sql b/src/test/regress/sql/object_address.sql index 9cf8097124..68e7cb0eb3 100644 --- a/src/test/regress/sql/object_address.sql +++ b/src/test/regress/sql/object_address.sql @@ -36,6 +36,9 @@ CREATE SERVER "integer" FOREIGN DATA WRAPPER addr_fdw; CREATE USER MAPPING FOR regtest_addr_user SERVER "integer"; ALTER DEFAULT PRIVILEGES FOR ROLE regtest_addr_user IN SCHEMA public GRANT ALL ON TABLES TO regtest_addr_user; ALTER DEFAULT PRIVILEGES FOR ROLE regtest_addr_user REVOKE DELETE ON TABLES FROM regtest_addr_user; +CREATE TRANSFORM FOR int LANGUAGE SQL ( + FROM SQL WITH FUNCTION varchar_transform(internal), + TO SQL WITH FUNCTION int4recv(internal)); -- test some error cases SELECT pg_get_object_address('stone', '{}', '{}'); @@ -74,7 +77,7 @@ BEGIN ('operator'), ('operator class'), ('operator family'), ('rule'), ('trigger'), ('text search parser'), ('text search dictionary'), ('text search template'), ('text search configuration'), - ('policy'), ('user mapping'), ('default acl'), + ('policy'), ('user mapping'), ('default acl'), ('transform'), ('operator of access method'), ('function of access method') LOOP FOR names IN VALUES ('{eins}'), ('{addr_nsp, zwei}'), ('{eins, zwei, drei}') @@ -162,7 +165,8 @@ WITH objects (type, name, args) AS (VALUES ('default acl', '{regtest_addr_user}', '{r}'), -- extension -- event trigger - ('policy', '{addr_nsp, gentable, genpol}', '{}') + ('policy', '{addr_nsp, gentable, genpol}', '{}'), + ('transform', '{int}', '{sql}') ) SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.subobjid)).*, -- test roundtrip through pg_identify_object_as_address