Can I use variable to store sql data - II - Mailing list pgsql-patches

From NosyMan
Subject Can I use variable to store sql data - II
Date
Msg-id 200510170959.49678.nosyman@gmail.com
Whole thread Raw
Responses Re: Can I use variable to store sql data - II
List pgsql-patches
Hi,

The scenario:
1. SELECT id_product FROM products WHERE product_code='PRD-030';

Now I want to insert id_product into another table :

2. INSERT INTO product_sales( id_product, sale_date)
    INSERT INTO product_sales( id_product, sale_date)
    INSERT INTO product_sales( id_product, sale_date)

As you can see the 'id_product' is not known. I know one solution:
INSERT INTO product_sales(  (SELECT id_product FROM products WHERE
product_code='PRD-030'), sale_date)
... but I don't like it very mutch.

Can I set id_product from statement 1 to a variable and use that variable into
statements 2.


Thanks.

pgsql-patches by date:

Previous
From: Joe Conway
Date:
Subject: Re: [HACKERS] Patching dblink.c to avoid warning about
Next
From: NosyMan
Date:
Subject: Can I use variable to store sql data?