Received: from wallace.ece.rice.edu (root@wallace.ece.rice.edu [128.42.12.154]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA96281 for ; Fri, 10 Dec 1999 11:54:55 -0500 (EST) (envelope-from reedstrm@wallace.ece.rice.edu) Received: by wallace.ece.rice.edu via sendmail from stdin id (Debian Smail3.2.0.102) for pgsql-sql@postgresql.org; Fri, 10 Dec 1999 10:54:40 -0600 (CST) Date: Fri, 10 Dec 1999 10:54:40 -0600 From: "Ross J. Reedstrom" To: Eric BARROCA , pgsql-sql@postgresql.org Subject: Re: [SQL] INSERT and SELECT Message-ID: <19991210105440.A14616@rice.edu> References: <87n1riu7bx.fsf@venus.fondation> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/1.0i In-Reply-To: ; from rison@biochemistry.ucl.ac.uk on Fri, Dec 10, 1999 at 04:31:32PM +0000 I wasn't going to respond to this, but there are two, almost correct, replies, so I thought I should edit a bit: On Fri, Dec 10, 1999 at 04:31:32PM +0000, Stuart Rison wrote: > If you go into psql and type \h INSERT or \h SELECT you'll get the syntax > for these: Good idea ;-) > > 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"; Oops, the | is between the VALUES and SELECT clauses, so that should be: INSERT INTO table SELECT oid, 'test' FROM membre WHERE email='toto@toto.com'; Note that the other followup, about quote marks, is also correct. > > > 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"); SELECT oid, 'test' INTO other_table FROM membre WHERE email='toto@toto.com'); Just quote marks, here.