PGSQL PERFORMANCE 15 RE INSERT QUESTION
From: sarlavk@no-spam (sarlav kumar)
Subject: Re: INSERT question
Date: Mon, 13 Dec 2004 10:33:08 -0800 (PST)


Thanks guys!! that worked!:)

Michael Adler <adler@no-spam> wrote: On Mon, Dec 13, 2004 at 08:28:39AM -0800, sarlav kumar wrote:
> INSERT into merchant_buyer_country (merchant_id,country,enabled,group_id) values (1203,
> (SELECT code FROM country WHERE send IS NOT NULL OR receive IS NOT NULL), 'true',1);

> > I tried this, but I get the following problem:
> ERROR: More than one tuple returned by a subselect used as an expression.

INSERT into merchant_buyer_country (merchant_id,country,enabled,group_id) SELECT 1203, code FROM country WHERE send IS NOT NULL OR receive IS NOT NULL;

-Mike Adler
Bruno Wolff III <bruno@no-spam> wrote:
On Mon, Dec 13, 2004 at 08:28:39 -0800,
sarlav kumar wrote:
> > Is there a way to write the INSERT as follows?
> > INSERT into merchant_buyer_country (merchant_id,country,enabled,group_id) values (1203,
> (SELECT code FROM country WHERE send IS NOT NULL OR receive IS NOT NULL), 'true',1);

>
You have to use a SELECT instead of the VAlues clause. Something like the following should work:
INSERT INTO merchant_buyer_country (merchant_id, country, enabled, group_id)
SELECT 1203, code, TRUE, 1 FROM country WHERE send IS NOT NULL OR receive IS NOT NULL ;

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@no-spam

---------------------------------
Do you Yahoo!?
All your favorites on one personal page – Try My Yahoo!
<DIV>Thanks guys!! that worked!:)</DIV>
<DIV><BR><B><I>Michael Adler <adler@no-spam</I></B> wrote: </DIV>
<DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">On Mon, Dec 13, 2004 at 08:28:39AM -0800, sarlav kumar wrote:<BR>> INSERT into merchant_buyer_country (merchant_id,country,enabled,group_id) values (1203, <BR>> (SELECT code FROM country WHERE send IS NOT NULL OR receive IS NOT NULL), 'true',1);<BR>> <BR>> I tried this, but I get the following problem:<BR>> ERROR: More than one tuple returned by a subselect used as an expression.<BR><BR>INSERT into merchant_buyer_country (merchant_id,country,enabled,group_id) <BR>SELECT 1203, code FROM country WHERE send IS NOT NULL OR receive IS NOT NULL;<BR><BR>-Mike Adler<BR></BLOCKQUOTE><BR><B><I>Bruno Wolff III <bruno@no-spam</I></B> wrote:</DIV>

<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">On Mon, Dec 13, 2004 at 08:28:39 -0800,<BR>sarlav kumar <SARLAVK@no-spam>wrote:<BR>> <BR>> Is there a way to write the INSERT as follows?<BR>> <BR>> INSERT into merchant_buyer_country (merchant_id,country,enabled,group_id) values (1203, <BR>> (SELECT code FROM country WHERE send IS NOT NULL OR receive IS NOT NULL), 'true',1);<BR>> <BR><BR>You have to use a SELECT instead of the VAlues clause. Something like the<BR>following should work:<BR>INSERT INTO merchant_buyer_country (merchant_id, country, enabled, group_id)<BR>SELECT 1203, code, TRUE, 1 FROM country<BR>WHERE send IS NOT NULL OR receive IS NOT NULL<BR>;<BR><BR>---------------------------(end of broadcast)---------------------------<BR>TIP 1: subscribe and unsubscribe commands go to majordomo@no-spam<BR></BLOCKQUOTE><p>

<hr size=1>Do you Yahoo!?<br> All your favorites on one personal page – <a href="http://my.yahoo.com">Try My Yahoo!</a>