From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: pgsql-sql@hub.org
Subject: Re: [SQL] Re: Another nut to crack with insertion into tables... *sigh*
Date: Mon, 28 Sep 1998 18:20:54 +0200
Message-ID: <l0311070ab23566f0a90d@[147.233.159.109]> (raw)
In-Reply-To: <20074.906991330@sss.pgh.pa.us>
References: <199809280300.XAA18545@hub.org>
At 16:02 +0200 on 28/9/98, Tom Lane wrote:
>
> I believe sub-selects are currently only supported in WHERE clauses.
> Supporting them elsewhere is on the TODO list for a future release
> (no, 6.4 won't have it). In the meantime you'll have to read back
> the result of the sub-select and include it in the text of the INSERT.
>
> (I'm not sure whether the SQL spec allows a select in an INSERT like this
> anyway. What happens if the sub-select returns no tuples, or more than
> one tuple?)
First, there is an exception which is supposed to be thrown in such a case.
But anyway, there is no reason to do things like this. Read the "insert"
manpage. The syntax is:
insert into classname
[(att.expr-1 [,att_expr.i] )]
{values (expression1 [,expression-i] ) |
select expression1 [,expression-i]
[from from-list] [where qual]
So, you should format your insert like this:
INSERT INTO my_table
(int_field, text_field, another_int_field, another_text_field )
SELECT 15, 'The Wind in the Willows', foreign_int_field, foreign_text_field
FROM foreign_table
WHERE ...
Everything which you want inserted literally, you put as constants on the
select list. It's a valid expression. Anything you want from the other
table (or tables!), you mention by its field name.
Very simple, and has been working for ages.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
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: herouth@oumail.openu.ac.il, pgsql-sql@hub.org
Subject: Re: [SQL] Re: Another nut to crack with insertion into tables... *sigh*
In-Reply-To: <l0311070ab23566f0a90d@[147.233.159.109]>
References: <199809280300.XAA18545@hub.org> <l0311070ab23566f0a90d@[147.233.159.109]>
* 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