Re: [SQL] INSERT and SELECT

Поиск
Список
Период
Сортировка
От Ross J. Reedstrom
Тема Re: [SQL] INSERT and SELECT
Дата
Msg-id 19991210105440.A14616@rice.edu
обсуждение исходный текст
Ответ на Re: [SQL] INSERT and SELECT  (Stuart Rison <rison@biochemistry.ucl.ac.uk>)
Список pgsql-sql
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.


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Nikolay Mijaylov"
Дата:
Сообщение: Re: [SQL] INSERT and SELECT
Следующее
От: wieck@debis.com (Jan Wieck)
Дата:
Сообщение: Re: [SQL] INSERT and SELECT