Re: INSERT question

From: Bruno Wolff III
Subject: Re: INSERT question
Date: ,
Msg-id: 20041213164952.GC546@wolff.to
(view: Whole thread, Raw)
In response to: INSERT question  (sarlav kumar)
List: pgsql-novice

Tree view

INSERT question  (sarlav kumar, )
 Re: INSERT question  (Bruno Wolff III, )
 Re: INSERT question  (Tom Lane, )
  Re: INSERT question  (sarlav kumar, )
 Re: [PERFORM] INSERT question  (george young, )

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
;


pgsql-novice by date:

From: sarlav kumar
Date:
Subject: Re: INSERT question
From: "Tjibbe Rijpma"
Date:
Subject: How to create a (recursive) function that get all parents from: a tree with loops in it.