Re: Question on utility statements and parameterization - Mailing list pgsql-general

From Pavel Stehule
Subject Re: Question on utility statements and parameterization
Date
Msg-id CAFj8pRA69rth8WQOaMfj1FtzW_5CrtKuPtq5MH90e9+ftEPdhQ@mail.gmail.com
Whole thread Raw
In response to Question on utility statements and parameterization  (Chris Travers <chris.travers@gmail.com>)
Responses Re: Question on utility statements and parameterization
List pgsql-general
Hello

2011/7/19 Chris Travers <chris.travers@gmail.com>:
> Hi all;
>
> As I understand, utility statements are not generally parameterized, so:
>
> postgres=# alter user test123 with password 'foo' valid until now() +
> '1 day'::interval;
> ERROR:  syntax error at or near "now"
> LINE 1: ...lter user test123 with password 'foo' valid until now() + '1...
>
> Is this by design?  If so, what is the reason?  If not, what would
> have to be done to change this?
>
> Best Wishes,
> Chris Travers
>

If I understand well , a utility has no plan, and a parameters are
implemented as plan's parameters.

you can use a dynamic sql in plpgql

DO $$
BEGIN
  EXECUTE 'ALTER USER test123 WITH PASSWORD 'foo' VALID UNTIL ' ||
to_char(CURRENT_DATE + 1, 'YYYY-MM-DD');
END;
$$;

Regards

Pavel

> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

pgsql-general by date:

Previous
From: Chris Travers
Date:
Subject: Question on utility statements and parameterization
Next
From: Chris Travers
Date:
Subject: Re: Question on utility statements and parameterization