Received: from mail-b.bcc.ac.uk (mail-b.bcc.ac.uk [144.82.100.22]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA88352 for ; Fri, 10 Dec 1999 11:25:03 -0500 (EST) (envelope-from rison@biochemistry.ucl.ac.uk) Received: from biochem.ucl.ac.uk (actually host bsmori1.biochem.ucl.ac.uk) by mail-b.bcc.ac.uk with SMTP (XT-PP) with ESMTP; Fri, 10 Dec 1999 16:22:17 +0000 Received: from bsmlx17.biochem.ucl.ac.uk (bsmlx17 [128.40.46.142]) by biochem.ucl.ac.uk (8.9.2/8.9.1) with ESMTP id QAA09431; Fri, 10 Dec 1999 16:22:30 GMT Received: from localhost (rison@localhost) by bsmlx17.biochem.ucl.ac.uk (8.9.3/8.6.6) with ESMTP id QAA13421; Fri, 10 Dec 1999 16:31:32 GMT X-Authentication-Warning: bsmlx17.biochem.ucl.ac.uk: rison owned process doing -bs Date: Fri, 10 Dec 1999 16:31:32 +0000 (GMT) From: Stuart Rison X-Sender: rison@bsmlx17 To: Eric BARROCA cc: pgsql-sql@postgreSQL.org Subject: Re: [SQL] INSERT and SELECT In-Reply-To: <87n1riu7bx.fsf@venus.fondation> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=X-UNKNOWN Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.org id LAA88353 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 : > > ************ > 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