Re: Difficulty passing in an array of values to EXECUTE - Mailing list pgsql-general

From Richard Huxton
Subject Re: Difficulty passing in an array of values to EXECUTE
Date
Msg-id 453F4DE7.7010509@archonet.com
Whole thread Raw
In response to Difficulty passing in an array of values to EXECUTE SELECT statement  (Nick Rowlands <nick.rowlands@scotwebshops.com>)
Responses Re: Difficulty passing in an array of values to EXECUTE
List pgsql-general
Nick Rowlands wrote:
> Hi there,
>
> I'm having trouble creating a function using plpgsql. I cannot pass the
> array 'productids' to the ANY construct of the IN EXECUTE SELECT
> statement. Any ideas on what I'm doing wrong would be most appreciated.
> Here's the function:

>     FOR row IN EXECUTE 'SELECT p.id, sku, description, base_price,
> j.name AS jname, r.name AS rname
>     FROM products2 p
>     INNER JOIN jewellery_types j ON j.id = p.jewellery_type
>     INNER JOIN ranges r ON r.id = p.range_id
>     WHERE p.id = ANY(productids)' || filter_jewellery LOOP

EXECUTE takes a string, so you're giving it the word "productids" not
the contents of the variable with that name.

You'll need to generate a string containing comma-separated values (or
the array definition) and use that.
--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Nick Rowlands
Date:
Subject: Difficulty passing in an array of values to EXECUTE SELECT statement
Next
From: "William Leite Araújo"
Date:
Subject: Re: Difficulty passing in an array of values to EXECUTE