Re: doing %-expansion in plpgsql RAISE USING - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: doing %-expansion in plpgsql RAISE USING
Date
Msg-id 162867790908040656x4ea28efdyfa312dd233ff8510@mail.gmail.com
Whole thread Raw
In response to doing %-expansion in plpgsql RAISE USING  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-hackers
Hello

2009/8/4 Alvaro Herrera <alvherre@commandprompt.com>:
> Hi,
>
> It seems there's no way to do %-expansion in plpgsql when one is using
> RAISE USING:
>
> alvherre=# create or replace function f () returns void language plpgsql as $$
> begin
>  raise using message = 'hello %' || 'world';
>  return;
> end;
> $$;
> CREATE FUNCTION
> alvherre=# select f();
> ERROR:  hello %world
>
>

parameter is expression, so we could to define operator % like

text % any

% isn't defined for text so this is possible. This operator should be
generally used, not only in RAISE attribs.


> I would like the % to be expanded to some argument, but obviously
> there's no way to pass the arguments that it should expand to.  We could
> do something like
>
> RAISE USING message = 'hello %st %', args = 1, 'world'
>

RAISE USING message = 'hello %st %' % (1, 'world')

??

or simple use custom variadic function

RAISE USING message= subst('hello %st %', 1, 'world')

good example for parser hook :)

Pavel

> but this is obviously going to be difficult, if not impossible, to
> implement in the grammar.  Perhaps
> RAISE USING message = 'brave %st %', args = (1, 'world')
>
> Thoughts?
>
> --
> Alvaro Herrera                                http://www.CommandPrompt.com/
> The PostgreSQL Company - Command Prompt, Inc.
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: doing %-expansion in plpgsql RAISE USING
Next
From: Stephen Frost
Date:
Subject: Re: SE-PostgreSQL Specifications