Re: computed values in plpgsql

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Sam Mason <sam(at)samason(dot)me(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: computed values in plpgsql
Date: 2009-09-29 16:30:42
Message-ID: 162867790909290930o3811f3d6q3fcf6d25cd209336@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/9/29 Sam Mason <sam(at)samason(dot)me(dot)uk>:
> On Tue, Sep 29, 2009 at 05:42:37PM +0200, Pavel Stehule wrote:
>> you cannot use double quotes. It's not php.
>
> Normally yes, but *inside* literals you do indeed want double quotes.
>
>
> I think the OP wants to be using quote_literal here.  I.e. instead of:
>
>  execute 'insert into foo_something select (''' || new::text || '''::foo).*';
>
> it wants to be closer to:
>
>  execute 'insert into foo_something select (foo ' || quote_literal(new) || ').*;';
>
> but it's a bit fiddly and I may have got that wrong somewhere else.

I afraid so this technique is very buggy. You need unpacked serialised
record. And the result have to be valid sql literal.

postgres=# create type t as (name varchar, addr varchar);
CREATE TYPE
postgres=# select row('Pavel Stehule','Benesov')::t;
row
---------------------------
("Pavel Stehule",Benesov)
(1 row)

postgres=# select (row('Pavel Stehule','Benesov')::t).*;
name | addr
---------------+---------
Pavel Stehule | Benesov
(1 row)

but you need 'Pavel Stehule','Benesov'

you cannot apply quote literal on two or more columns. I thing, so
this isn't possible now.

Pavel

>
> --
>  Sam  http://samason.me.uk/
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2009-09-29 16:42:38 Re: Upgrade db format without older version of PostgreSQL
Previous Message Devrim GÜNDÜZ 2009-09-29 16:29:21 Re: Upgrade db format without older version of PostgreSQL