Search Postgresql Archives

Re: Can I use variable to store sql data?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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.

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux