Re: [SQL] INSERT and SELECT

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: Eric BARROCA <eric(at)netsystems(dot)fr>, pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] INSERT and SELECT
Date: 1999-12-10 16:54:40
Message-ID: 19991210105440.A14616@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)toto(dot)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(at)toto(dot)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(at)toto(dot)com");

SELECT oid, 'test' INTO other_table FROM membre WHERE
email='toto(at)toto(dot)com');

Just quote marks, here.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Wieck 1999-12-10 16:57:57 Re: [SQL] INSERT and SELECT
Previous Message Eric BARROCA 1999-12-10 16:49:35 Re: [SQL] INSERT and SELECT