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

From Ross J. Reedstrom
Subject Re: [SQL] INSERT and SELECT
Date
Msg-id 19991210105440.A14616@rice.edu
Whole thread Raw
In response to Re: [SQL] INSERT and SELECT  (Stuart Rison <rison@biochemistry.ucl.ac.uk>)
List 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 by date:

Previous
From: "Nikolay Mijaylov"
Date:
Subject: Re: [SQL] INSERT and SELECT
Next
From: wieck@debis.com (Jan Wieck)
Date:
Subject: Re: [SQL] INSERT and SELECT