Re: [SQL] INSERT and SELECT

Поиск
Список
Период
Сортировка
От Stuart Rison
Тема Re: [SQL] INSERT and SELECT
Дата
Msg-id Pine.LNX.4.10.9912101627190.5807-100000@bsmlx17
обсуждение исходный текст
Ответ на INSERT and SELECT  (Eric BARROCA <eric@netsystems.fr>)
Ответы Re: [SQL] INSERT and SELECT  ("Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>)
manually set serial type  (rob caSSon <rob@styro.lib.muohio.edu>)
Список 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 по дате отправления:

Предыдущее
От: Eric BARROCA
Дата:
Сообщение: INSERT and SELECT
Следующее
От:
Дата:
Сообщение: Re: [SQL] INSERT and SELECT