Re: Simple SQL question, need help. - Mailing list pgsql-general

From Tom Lane
Subject Re: Simple SQL question, need help.
Date
Msg-id 13188.991066800@sss.pgh.pa.us
Whole thread Raw
In response to Simple SQL question, need help.  (fyzfeech@yahoo.com (feech))
List pgsql-general
fyzfeech@yahoo.com (feech) writes:
> INSERT INTO results (PlayerID, Position) values (SELECT players.id
> from players WHERE name = 'Chuck', 4 );

You need to put parentheses around the sub-select used as an
expression:

INSERT INTO results (PlayerID, Position) values ((SELECT players.id
from players WHERE name = 'Chuck'), 4 );

A more conventional way to get the same result is

INSERT INTO results (PlayerID, Position)
  SELECT id, 4 FROM players WHERE name = 'Chuck';

            regards, tom lane

pgsql-general by date:

Previous
From: Denis Gasparin
Date:
Subject: Kylix, dbexpress & PostgreSql
Next
From: Tom Lane
Date:
Subject: Re: restore pg_dumpall problem with update 7.0.3 to 7.1.1