Skip site navigation (1) Skip section navigation (2)

Can I use variable to store sql data - II

From: NosyMan <nosyman(at)gmail(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: Can I use variable to store sql data - II
Date: 2005-10-17 06:59:49
Message-ID: 200510170959.49678.nosyman@gmail.com (view raw or flat)
Thread:
Lists: 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.

Responses

pgsql-patches by date

Next:From: Bruce MomjianDate: 2005-10-17 12:36:00
Subject: Re: [HACKERS] Patching dblink.c to avoid warning about
Previous:From: NosyManDate: 2005-10-17 06:55:50
Subject: Can I use variable to store sql data?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group