From: Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>
To: Eric BARROCA <eric@netsystems.fr>
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] INSERT and SELECT
Date: Fri, 10 Dec 1999 10:54:40 -0600
Message-ID: <19991210105440.A14616@rice.edu> (raw)
In-Reply-To: <Pine.LNX.4.10.9912101627190.5807-100000@bsmlx17>
References: <87n1riu7bx.fsf@venus.fondation>
<Pine.LNX.4.10.9912101627190.5807-100000@bsmlx17>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: reedstrm@wallace.ece.rice.edu, eric@netsystems.fr
Subject: Re: [SQL] INSERT and SELECT
In-Reply-To: <19991210105440.A14616@rice.edu>
References: <87n1riu7bx.fsf@venus.fondation> <Pine.LNX.4.10.9912101627190.5807-100000@bsmlx17> <19991210105440.A14616@rice.edu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox