Skip to content

Commit 0779f2b

Browse files
committed
Fix parse tree of DROP TRANSFORM and COMMENT ON TRANSFORM
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
1 parent b82a7be commit 0779f2b

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

contrib/hstore_plperl/expected/create_transform.out

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@ CREATE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION internal_in(
2323
ERROR: first argument of transform function must be type "internal"
2424
CREATE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal), TO SQL WITH FUNCTION plperl_to_hstore(internal)); -- ok
2525
CREATE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal), TO SQL WITH FUNCTION plperl_to_hstore(internal)); -- fail
26-
ERROR: transform for type hstore language plperl already exists
26+
ERROR: transform for type hstore language "plperl" already exists
2727
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
2828
CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal)); -- ok
2929
CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (TO SQL WITH FUNCTION plperl_to_hstore(internal)); -- ok
30+
COMMENT ON TRANSFORM FOR hstore LANGUAGE plperl IS 'test';
3031
DROP TRANSFORM IF EXISTS FOR fake_type LANGUAGE plperl;
3132
NOTICE: type "fake_type" does not exist, skipping
3233
DROP TRANSFORM IF EXISTS FOR hstore LANGUAGE fake_lang;
33-
NOTICE: transform for type hstore language fake_lang does not exist, skipping
34+
NOTICE: transform for type hstore language "fake_lang" does not exist, skipping
3435
DROP TRANSFORM FOR foo LANGUAGE plperl;
3536
ERROR: type "foo" does not exist
3637
DROP TRANSFORM FOR hstore LANGUAGE foo;
3738
ERROR: language "foo" does not exist
3839
DROP TRANSFORM FOR hstore LANGUAGE plperl;
3940
DROP TRANSFORM IF EXISTS FOR hstore LANGUAGE plperl;
40-
NOTICE: transform for type hstore language plperl does not exist, skipping
41+
NOTICE: transform for type hstore language "plperl" does not exist, skipping
4142
DROP FUNCTION hstore_to_plperl(val internal);
4243
DROP FUNCTION plperl_to_hstore(val internal);
4344
CREATE EXTENSION hstore_plperl;

contrib/hstore_plperl/sql/create_transform.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION h
2626
CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (FROM SQL WITH FUNCTION hstore_to_plperl(internal)); -- ok
2727
CREATE OR REPLACE TRANSFORM FOR hstore LANGUAGE plperl (TO SQL WITH FUNCTION plperl_to_hstore(internal)); -- ok
2828

29+
COMMENT ON TRANSFORM FOR hstore LANGUAGE plperl IS 'test';
30+
2931
DROP TRANSFORM IF EXISTS FOR fake_type LANGUAGE plperl;
3032
DROP TRANSFORM IF EXISTS FOR hstore LANGUAGE fake_lang;
3133
DROP TRANSFORM FOR foo LANGUAGE plperl;

src/backend/catalog/objectaddress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ get_object_address(ObjectType objtype, List *objname, List *objargs,
770770
case OBJECT_TRANSFORM:
771771
{
772772
TypeName *typename = (TypeName *) linitial(objname);
773-
char *langname = (char *) linitial(objargs);
773+
char *langname = strVal(linitial(objargs));
774774
Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
775775
Oid lang_id = get_language_oid(langname, missing_ok);
776776

src/backend/commands/dropcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ does_not_exist_skipping(ObjectType objtype, List *objname, List *objargs)
369369
case OBJECT_TRANSFORM:
370370
if (!type_in_list_does_not_exist_skipping(objname, &msg, &name))
371371
{
372-
msg = gettext_noop("transform for type %s language %s does not exist, skipping");
372+
msg = gettext_noop("transform for type %s language \"%s\" does not exist, skipping");
373373
name = TypeNameToString((TypeName *) linitial(objname));
374-
args = (char *) linitial(objargs);
374+
args = strVal(linitial(objargs));
375375
}
376376
break;
377377
case OBJECT_TRIGGER:

src/backend/commands/functioncmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ CreateTransform(CreateTransformStmt *stmt)
18671867
if (!stmt->replace)
18681868
ereport(ERROR,
18691869
(errcode(ERRCODE_DUPLICATE_OBJECT),
1870-
errmsg("transform for type %s language %s already exists",
1870+
errmsg("transform for type %s language \"%s\" already exists",
18711871
format_type_be(typeid),
18721872
stmt->lang)));
18731873

src/backend/parser/gram.y

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,7 +4112,7 @@ AlterExtensionContentsStmt:
41124112
n->action = $4;
41134113
n->objtype = OBJECT_TRANSFORM;
41144114
n->objname = list_make1($7);
4115-
n->objargs = list_make1($9);
4115+
n->objargs = list_make1(makeString($9));
41164116
$$ = (Node *)n;
41174117
}
41184118
| ALTER EXTENSION name add_drop TYPE_P Typename
@@ -5773,7 +5773,7 @@ CommentStmt:
57735773
CommentStmt *n = makeNode(CommentStmt);
57745774
n->objtype = OBJECT_TRANSFORM;
57755775
n->objname = list_make1($5);
5776-
n->objargs = list_make1($7);
5776+
n->objargs = list_make1(makeString($7));
57775777
n->comment = $9;
57785778
$$ = (Node *) n;
57795779
}
@@ -7389,7 +7389,7 @@ DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_d
73897389
DropStmt *n = makeNode(DropStmt);
73907390
n->removeType = OBJECT_TRANSFORM;
73917391
n->objects = list_make1(list_make1($5));
7392-
n->arguments = list_make1(list_make1($7));
7392+
n->arguments = list_make1(list_make1(makeString($7)));
73937393
n->behavior = $8;
73947394
n->missing_ok = $3;
73957395
$$ = (Node *)n;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy