From: Stuart Rison <rison@biochemistry.ucl.ac.uk>
To: Eric BARROCA <eric@netsystems.fr>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] INSERT and SELECT
Date: Fri, 10 Dec 1999 16:31:32 +0000 (GMT)
Message-ID: <Pine.LNX.4.10.9912101627190.5807-100000@bsmlx17> (raw)
In-Reply-To: <87n1riu7bx.fsf@venus.fondation>
If you go into psql and type \h INSERT or \h SELECT you'll get the syntax
for these:
test_capture=> \h INSERT
Command: insert
Description: insert tuples
Syntax:
INSERT INTO class_name [(attr1, ...attrN)]
VALUES (expr1,..exprN) |
SELECT [DISTINCT [ON attrN]]
expr1, ...exprN
[FROM from_clause]
[WHERE qual]
[GROUP BY group_list]
[HAVING having_clause]
[UNION [ALL] SELECT ...];
So what you want is:
INSERT INTO table VALUES SELECT oid, 'test' FROM membre WHERE
email="toto@toto.com";
Assuming table 'table' already exists.
Or
test_capture=> \h SELECT
Command: select
Description: retrieve tuples
Syntax:
SELECT [DISTINCT [ON attrN]] expr1 [AS attr1], ...exprN
[INTO [TABLE] class_name]
[FROM from_list]
[WHERE qual]
[GROUP BY group_list]
[HAVING having_clause]
[ORDER BY attr1 [ASC|DESC] [USING op1], ...attrN ]
[UNION [ALL] SELECT ...];
SELECT oid, 'test' INTO other_table FROM membre WHERE
email="toto@toto.com");
which will create the appropriate funtion for you.
HTH,
S.
On 10 Dec 1999, Eric BARROCA wrote:
> Hi,
>
> I've tried this query with PostgreSQL, but it doesn't work. Could anyone
> explain me why and what must I do to get the same result ?
> Query example : "INSERT INTO table VALUES (
> (SELECT oid FROM membre WHERE email="toto@toto.com"),
> "test");"
> I get the error : "parse error near select".
>
> I've been searched in the manual and with deja.com but I haven't found
> something about this.
> This query works with mysql (and it's the only one query that works with
> this RDBMS ;-)
>
>
> Thanks,
>
> Éric.
>
> --
> Éric BARROCA | Logiciels Libres, Conception Intranet/Extranet,
> E-Mail: eric@netsystems.fr | Sites Web dynamiques, Commerce électronique,
> Tel: +33 (0)2 48 21 54 67 | Formations (Unix/Linux, Perl, etc.), Réseaux...
> GSM: +33 (0)6 16 35 33 25 | NetSystems : <http://www.netsystems.fr;
>
> ************
>
Stuart C. G. Rison
Department of Biochemistry and Molecular Biology
6th floor, Darwin Building, University College London (UCL)
Gower Street, London, WC1E 6BT, United Kingdom
Tel. 0207 504 2303, Fax. 0207 380 7193
e-mail: rison@biochem.ucl.ac.uk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: rison@biochemistry.ucl.ac.uk, eric@netsystems.fr
Subject: Re: [SQL] INSERT and SELECT
In-Reply-To: <Pine.LNX.4.10.9912101627190.5807-100000@bsmlx17>
References: <87n1riu7bx.fsf@venus.fondation> <Pine.LNX.4.10.9912101627190.5807-100000@bsmlx17>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox