Re: SELECT ROW(t.*) FROM table t and nulls with textual representation? - Mailing list pgsql-general

From Merlin Moncure
Subject Re: SELECT ROW(t.*) FROM table t and nulls with textual representation?
Date
Msg-id b42b73150912080759r563a1fe2t39ac585e92ab859f@mail.gmail.com
Whole thread Raw
In response to SELECT ROW(t.*) FROM table t and nulls with textual representation?  ("Teemu Juntunen" <teemu.juntunen@e-ngine.fi>)
List pgsql-general
On Tue, Dec 8, 2009 at 5:43 AM, Teemu Juntunen
<teemu.juntunen@e-ngine.fi> wrote:
> Hello,
>
> is there any possibility to get null-values as text 'null' from
> dynamic select expression like
>
> SELECT ROW(t.*) FROM table t
>
> Normally you get
>
> (t1,t2,t3,,t5,,,)
>
> How can you get
>
> (t1,t2,t3,null,t5,null,null,null)
>
> I would like to use the result with dynamic update expression and update
> doesn't like of empty values, so
>
> UPDATE SET (t1,t2,t3,t4,t5,t6,t7,t8) = (t1,t2,t3,,t5,,,)

It can't be done.  The problem is that the update statement has a
funky syntax which is not composite type friendly.  What I would
personally like to be table to do is:
update foo set foo = (x,y,z)::foo where...
then you could do:
update foo set foo = '(a,b,)'::foo where...

Couple of posssible workarounds:
*) If you are willing to put the fields you are updating as a block
into a composite type, then you could update them as a block:
create table bar as (...)
create table foo (b bar, ...)
update foo set bar = ()::bar where...;

This isn't a general solution obviously.

*) convert your update to insert+delete:
delete from foo where...
insert into foo select '(a,b,)'::foo;

watch that race condition!

merlin

pgsql-general by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: LDAP configuration changes in 8.4?
Next
From: Glyn Astill
Date:
Subject: Re: LDAP configuration changes in 8.4?