Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix parse tree of DROP TRANSFORM and COMMENT ON TRANSFORM
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 19 May 2015 02:55:14 +0000 (22:55 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Tue, 19 May 2015 02:55:14 +0000 (22:55 -0400)
The plain C string language name needs to be wrapped in makeString() so
that the parse tree is copyable.  This is detectable by
-DCOPY_PARSE_PLAN_TREES.  Add a test case for the COMMENT case.

Also make the quoting in the error messages more consistent.

discovered by Tom Lane

contrib/hstore_plperl/expected/create_transform.out
contrib/hstore_plperl/sql/create_transform.sql
src/backend/catalog/objectaddress.c
src/backend/commands/dropcmds.c
src/backend/commands/functioncmds.c
src/backend/parser/gram.y

index 1661d48185c8684aa6998120a993d224571243ed..c588d33ab84982543b3271c0c1b07dfad30e9f67 100644 (file)
@@ -23,21 +23,22 @@ CREATE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION internal_in(
 ERROR:  first argument of transform function must be type "internal"
 CREATE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal), TO SQL WITH FUNCTION plperl_to_hstore(internal));  -- ok
 CREATE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal), TO SQL WITH FUNCTION plperl_to_hstore(internal));  -- fail
-ERROR:  transform for type hstore language plperl already exists
+ERROR:  transform for type hstore language "plperl" already exists
 CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal), TO SQL WITH FUNCTION plperl_to_hstore(internal));  -- ok
 CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal));  -- ok
 CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (TO SQL WITH FUNCTION plperl_to_hstore(internal));  -- ok
+COMMENT ON TRANSFORM FOR hstore LANGUAGE plperl IS 'test';
 DROP TRANSFORM IF EXISTS FOR fake_type LANGUAGE plperl;
 NOTICE:  type "fake_type" does not exist, skipping
 DROP TRANSFORM IF EXISTS FOR hstore LANGUAGE fake_lang;
-NOTICE:  transform for type hstore language fake_lang does not exist, skipping
+NOTICE:  transform for type hstore language "fake_lang" does not exist, skipping
 DROP TRANSFORM FOR foo LANGUAGE plperl;
 ERROR:  type "foo" does not exist
 DROP TRANSFORM FOR hstore LANGUAGE foo;
 ERROR:  language "foo" does not exist
 DROP TRANSFORM FOR hstore LANGUAGE plperl;
 DROP TRANSFORM IF EXISTS FOR hstore LANGUAGE plperl;
-NOTICE:  transform for type hstore language plperl does not exist, skipping
+NOTICE:  transform for type hstore language "plperl" does not exist, skipping
 DROP FUNCTION hstore_to_plperl(val internal);
 DROP FUNCTION plperl_to_hstore(val internal);
 CREATE EXTENSION hstore_plperl;
index 40477e313b990f28b466a06cb6a43e98db94d272..d0a12ada9f8f72bf246ff8615e4f6f8a7188e82a 100644 (file)
@@ -26,6 +26,8 @@ CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION h
 CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal));  -- ok
 CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (TO SQL WITH FUNCTION plperl_to_hstore(internal));  -- ok
 
+COMMENT ON TRANSFORM FOR hstore LANGUAGE plperl IS 'test';
+
 DROP TRANSFORM IF EXISTS FOR fake_type LANGUAGE plperl;
 DROP TRANSFORM IF EXISTS FOR hstore LANGUAGE fake_lang;
 DROP TRANSFORM FOR foo LANGUAGE plperl;
index a1f8ada83375ea9fe85ceb74486e3e96cdd61f23..8d98c5d9a63a4ae8103fe0373a0ab8f78107c625 100644 (file)
@@ -770,7 +770,7 @@ get_object_address(ObjectType objtype, List *objname, List *objargs,
            case OBJECT_TRANSFORM:
                {
                    TypeName   *typename = (TypeName *) linitial(objname);
-                   char       *langname = (char *) linitial(objargs);
+                   char       *langname = strVal(linitial(objargs));
                    Oid         type_id = LookupTypeNameOid(NULL, typename, missing_ok);
                    Oid         lang_id = get_language_oid(langname, missing_ok);
 
index 80a0eb6e9e787a4d3cca0f8dfe1e81a6d47e4001..78a1bf334d87460528624ec19084ceeadaa76b41 100644 (file)
@@ -369,9 +369,9 @@ does_not_exist_skipping(ObjectType objtype, List *objname, List *objargs)
        case OBJECT_TRANSFORM:
            if (!type_in_list_does_not_exist_skipping(objname, &msg, &name))
            {
-               msg = gettext_noop("transform for type %s language %s does not exist, skipping");
+               msg = gettext_noop("transform for type %s language \"%s\" does not exist, skipping");
                name = TypeNameToString((TypeName *) linitial(objname));
-               args = (char *) linitial(objargs);
+               args = strVal(linitial(objargs));
            }
            break;
        case OBJECT_TRIGGER:
index 9a92fdcff7d2b9ff87bdc1c173009c81e32c76b8..c1426dc9391958d6ad12fe3073e14a232b102f6e 100644 (file)
@@ -1867,7 +1867,7 @@ CreateTransform(CreateTransformStmt *stmt)
        if (!stmt->replace)
            ereport(ERROR,
                    (errcode(ERRCODE_DUPLICATE_OBJECT),
-                    errmsg("transform for type %s language %s already exists",
+                    errmsg("transform for type %s language \"%s\" already exists",
                            format_type_be(typeid),
                            stmt->lang)));
 
index 46f2229b68c45fd88a7d185388a81c4550a9fad7..709f3fb7c3318d78308190a932133f356dec5468 100644 (file)
@@ -4112,7 +4112,7 @@ AlterExtensionContentsStmt:
                    n->action = $4;
                    n->objtype = OBJECT_TRANSFORM;
                    n->objname = list_make1($7);
-                   n->objargs = list_make1($9);
+                   n->objargs = list_make1(makeString($9));
                    $$ = (Node *)n;
                }
            | ALTER EXTENSION name add_drop TYPE_P Typename
@@ -5773,7 +5773,7 @@ CommentStmt:
                    CommentStmt *n = makeNode(CommentStmt);
                    n->objtype = OBJECT_TRANSFORM;
                    n->objname = list_make1($5);
-                   n->objargs = list_make1($7);
+                   n->objargs = list_make1(makeString($7));
                    n->comment = $9;
                    $$ = (Node *) n;
                }
@@ -7389,7 +7389,7 @@ DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_d
                    DropStmt *n = makeNode(DropStmt);
                    n->removeType = OBJECT_TRANSFORM;
                    n->objects = list_make1(list_make1($5));
-                   n->arguments = list_make1(list_make1($7));
+                   n->arguments = list_make1(list_make1(makeString($7)));
                    n->behavior = $8;
                    n->missing_ok = $3;
                    $$ = (Node *)n;