Re: Can I use variable to store sql data? - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: Can I use variable to store sql data?
Date
Msg-id 20051029150953.GA29677@wolff.to
Whole thread Raw
List pgsql-general
Please post questions to relevant lists. This question did not belong on
the patches list. I have moved the discussion to the general list.

Please don't reply to other threads to start new ones. This messes up the
archives and won't help people see your question.

On Mon, Oct 17, 2005 at 09:55:50 +0300,
  NosyMan <nosyman@gmail.com> wrote:
> Hi,
>
> The scenario:
> SELECT id_product FROM products WHERE product_code='PRD-030';
>
> Now I want to insert id_product into another table :
>
> INSERT INTO product_sales( id_product, sale_date)
> INSERT INTO product_sales( id_product, sale_date)
> INSERT INTO product_sales( id_product, sale_date)

You can do something like:
INSERT INTO product_sales values (
  (SELECT id_product FROM products WHERE product_code='PRD-030'),
  sales_date);

Also if id_product was just assigned a value from a sequence in the same
session, you could use the currval function to get its value.

pgsql-general by date:

Previous
From: Oleg Bartunov
Date:
Subject: Re: which charset use for cyrilic?
Next
From: Michael Fuhr
Date:
Subject: Re: querying while copying into a table and optimizations