Re: [SQL] INSERT and SELECT - Mailing list pgsql-sql

From Stuart Rison
Subject Re: [SQL] INSERT and SELECT
Date
Msg-id Pine.LNX.4.10.9912101627190.5807-100000@bsmlx17
Whole thread Raw
In response to INSERT and SELECT  (Eric BARROCA <eric@netsystems.fr>)
Responses Re: [SQL] INSERT and SELECT
manually set serial type
List pgsql-sql
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]
[USINGop1], ...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



pgsql-sql by date:

Previous
From: Eric BARROCA
Date:
Subject: INSERT and SELECT
Next
From:
Date:
Subject: Re: [SQL] INSERT and SELECT