Re: Another nut to crack with insertion into tables... *sigh* - Mailing list pgsql-sql

From Tom Lane
Subject Re: Another nut to crack with insertion into tables... *sigh*
Date
Msg-id 20074.906991330@sss.pgh.pa.us
Whole thread Raw
In response to Another nut to crack with insertion into tables... *sigh*  ("Gemeinschaft Studienarbeit Datenbanken" <oodbms@floppy.org>)
Responses Re: [SQL] Re: Another nut to crack with insertion into tables... *sigh*  (Herouth Maoz <herouth@oumail.openu.ac.il>)
List pgsql-sql
I dunno about arrays, but this one I think I can answer:

> insert into Rollenspiel
>         (Name, HerstellerID, Erscheinungsdatum,
>          Bestellnummer, Preisempfehlung,
>          Beschreibung,
>          Computertyp, Datentraegertyp,
>          System, AnzahlCharaktere, Typ,
>          Cluebook, SpielstandEditor)
>         values
>         ('Might & Magic I', (select HerstellerNummer from Hersteller
>                 where Name like '%Blueborg%'), '17.03.1986',
>          'role01', '29,50',
>          '{"Einfach irgendeine Beschreibung halt..."}',
>          '{"PC", "Mac", "c64", "Atari"}', '{"Diskette", "CD"}',
>          'Freies System', 6, 'Fantasy',
>          '{"Solution to Might & Magic Series", "The Might & Magic I Solution"}',
>          '{"http://www.mightandmagic.de/I/editors.html"}');
> ERROR:  parser: parse error at or near "select"

I believe sub-selects are currently only supported in WHERE clauses.
Supporting them elsewhere is on the TODO list for a future release
(no, 6.4 won't have it).  In the meantime you'll have to read back
the result of the sub-select and include it in the text of the INSERT.

(I'm not sure whether the SQL spec allows a select in an INSERT like this
anyway.  What happens if the sub-select returns no tuples, or more than
one tuple?)

            regards, tom lane

pgsql-sql by date:

Previous
From: Sferacarta Software
Date:
Subject: Re: [SQL] Another nut to crack with insertion into tables... *sigh*
Next
From: "Bryan White"
Date:
Subject: Setting current time on insert