Re: Allow COMMENT ON to accept an expression rather than just a string

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Abhijit Menon-Sen <ams(at)oryx(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Allow COMMENT ON to accept an expression rather than just a string
Date: 2009-04-11 18:16:53
Message-ID: 162867790904111116n5a0779fasd6250298224cae8e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> like (pseudo-code here)
>
>        execute('COMMENT ON foo IS $1', some_string);
>
> and let the out-of-line-parameter mechanism take care of quoting and
> escaping your string.  This doesn't work today, and I remember having
> seen complaints about that on the JDBC list.  So there's a use-case at
> least for allowing parameter symbols in place of string literals, if not
> fully general expressions.  But again, I think we'd want such a thing
> across all utility statements that can take string literals, not only
> COMMENT.

I afraid, this should have some not wanted impacts. When we allows
parametrisation in utility statements (and it should be nice), I
expect, so there will be people, that will write code like

CREATE OR REPLACE FUNCTION some_proc(tabname varchar)
RETURNS void AS $$
BEGIN
CREATE TABLE tabname(a integer); -- will work
INSERT INTO tabname VALUES(10); -- will not work
END;
$$ LANG ....

Now people know, so this cannot do it.

But the proc
CREATE OR REPLACE FUNCTION some_proc(tabname varchar)
RETURNS void AS $$
BEGIN
EXECUTE 'CREATE TABLE $1(a integer)' USING tabname;

is more readable than EXECUTE 'CREATE TABLE ' || tabname || '(....

so this isn't too simple

regards
Pavel Stehule

>
>                        regards, tom lane
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2009-04-11 18:40:57 Re: Allow COMMENT ON to accept an expression rather than just a string
Previous Message Tom Lane 2009-04-11 18:08:21 Re: Allow COMMENT ON to accept an expression rather than just a string