Re: doing %-expansion in plpgsql RAISE USING

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: doing %-expansion in plpgsql RAISE USING
Date: 2009-08-04 13:56:22
Message-ID: 162867790908040656x4ea28efdyfa312dd233ff8510@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

2009/8/4 Alvaro Herrera <alvherre(at)commandprompt(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2009-08-04 13:59:32 Re: SE-PostgreSQL Specifications
Previous Message Tom Lane 2009-08-04 13:51:57 Re: doing %-expansion in plpgsql RAISE USING