Re: libpq Prepared Statement with dynamic IN operator - Mailing list pgsql-general

From David G. Johnston
Subject Re: libpq Prepared Statement with dynamic IN operator
Date
Msg-id CAKFQuwZatW8rvCq6FbWnEkqqWzYNKWyt24mUpTSQNExUtruyrQ@mail.gmail.com
Whole thread Raw
In response to libpq Prepared Statement with dynamic IN operator  (Dave Greeko <davegreeko@yahoo.com>)
Responses Re: libpq Prepared Statement with dynamic IN operator  (Dave Greeko <davegreeko@yahoo.com>)
List pgsql-general
On Tue, Nov 24, 2020 at 12:14 PM Dave Greeko <davegreeko@yahoo.com> wrote:
Dear All,
I am having a hard time figuring out how prepare and execute a Prepared Statement with an "IN" operator in the WHERE clause using libpq. The total elements that will be passed to IN operator is dynamic and varied at runtime.
here is an example query:

select payload_id,ptime,frequency from codecs where tag IN (‘G729’,’GSM’);

The number of elements to filter for with this particular example is 2 but this varies at runtime (between 1 to 127 elements).
I would like to know what’s the proper syntax of the (char *query) parameter when calling the PQprepare() function.
I tried “select payload_id,ptime,frequency from codecs where tag=ANY(?)” but failed


ANY wants an array - you can either pass an array input literal and do "?::text[]" or you can pass a probably easier to write "csv" value and write "ANY(string_to_array(?, ','))".

David J.

pgsql-general by date:

Previous
From: Dave Greeko
Date:
Subject: libpq Prepared Statement with dynamic IN operator
Next
From: Paul Martinez
Date:
Subject: What is the best way to get the current number of worker processes?