Re: [INTERFACES] sql question - Mailing list pgsql-interfaces

From Tom Lane
Subject Re: [INTERFACES] sql question
Date
Msg-id 25795.944635216@sss.pgh.pa.us
Whole thread Raw
In response to sql question  (Joseph Shraibman <jks@p1.selectacast.net>)
List pgsql-interfaces
Joseph Shraibman <jks@p1.selectacast.net> writes:
> Is there any way to get something like this into valid sql?  Postgres
> doesn't like this:

> INSERT INTO application (key, creator, name) values ( 1 ,(select userkey
> from user where username = 'b' ), 'newapplication') ;

FWIW, this works in current sources and will be in the next release
(6.6 or 7.0 or whatever...).  6.5 doesn't support sub-selects in
target lists, which is what you have here.  You could work around it
with something like

INSERT INTO application SELECT 1, userkey, 'newapplication' FROM
user WHERE username = 'b';

although this doesn't mean quite the same thing (if there are multiple
user rows with username = 'b', the former raises an error while the
latter inserts multiple rows into application).

BTW: I dunno what version you are running, but "user" has been a
reserved word at least since 6.5.  Might be good to rename your table
before upgrading.
        regards, tom lane


pgsql-interfaces by date:

Previous
From: Douglas Thomson
Date:
Subject: Re: [INTERFACES] locking on database updates
Next
From: Tom Lane
Date:
Subject: Re: [INTERFACES] locking on database updates