Re: R: Re: R: Re: Weird EXECUTE ... USING behaviour

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>
Cc: adrian(dot)klaver(at)gmail(dot)com, Scott Mead <scott(dot)lists(at)enterprisedb(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: R: Re: R: Re: Weird EXECUTE ... USING behaviour
Date: 2010-01-14 18:17:16
Message-ID: 162867791001141017p4eedb971j2a1b7e7deab29aa@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2010/1/14 Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>:
> 2010/1/14 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>> 2010/1/14 Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>:
>>> 2010/1/14 Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>:
>>>> On Wednesday 13 January 2010 10:19:57 pm Vincenzo Romano wrote:
> ...
>>> CREATE OR REPLACE FUNCTION f()
>>> RETURNS VOID
>>> LANGUAGE plpgsql
>>> AS $function$
>>> DECLARE
>>>  cmd TEXT;
>>> BEGIN
>>>  EXECUTE '
>>>    SELECT $l0$ALTER TABLE test ALTER COLUMN i SET DEFAULT $1 $l0$
>>>  ' INTO cmd USING 42;
>>>  RAISE INFO '%',cmd;
>>> END;
>>> $function$
>>>
>>> SELECT f();
>>> INFO:  ALTER TABLE test ALTER COLUMN i SET DEFAULT $1
>>>
>>> The command to be executed is DML (SELECT). The substitution doesn't take place.
>>
>> yes. You cannot call SELECT 'ALTER ...'
>
> SELECT 'ALTER ...' is to select a text string into a variable!
> You mean the parse will give a look into my constant string to see
> whether I'm trying to build a dynamic DDL command?
> This would be awesome!
>

sorry. This is too much complicate.

Why do you use SELECT?

just

EXECUTE 'ALTER ... SET DEFAULT ' || 42.

There is other argument against USING + DDL. ALTER clause has syntax:

ALTER TABLE x SET DEFAULT expr.

but with USING clause you can pass only a value

Pavel

> --
> Vincenzo Romano
> NotOrAnd Information Technologies
> NON QVIETIS MARIBVS NAVTA PERITVS
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rodrigo Valdenegro 2010-01-14 18:54:15 PostreSQL PostgreSQL 8.1.18 and Tsearch2 context error
Previous Message Howard Cole 2010-01-14 17:03:35 Re: Configuration Optimisation