Re: libpq Prepared Statement with dynamic IN operator

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dave Greeko <davegreeko(at)yahoo(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: libpq Prepared Statement with dynamic IN operator
Date: 2020-11-24 21:18:11
Message-ID: 310537.1606252691@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dave Greeko <davegreeko(at)yahoo(dot)com> writes:
> I tried both and I am getting syntax error.

> char *query="select codec_id,fs_name,pt from codec_defs where pt = ANY(string_to_array(?, ','))";
> OR
> char *query="select codec_id,fs_name,pt from codec_defs where pt = ANY(?::text)";

> PGresult *res=PQprepare(conn,"codecs",query,1,NULL);

Well, your first problem is that "?" is not the parameter symbol
understood by libpq+backend. Try "$1". The other problem,
at least for the second version of that, is that you want to be
passing a text array not a single text value --- so it needs to
look more like "where pt = ANY($1::text[])".

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dave Greeko 2020-11-24 22:47:19 Re: libpq Prepared Statement with dynamic IN operator
Previous Message Dave Greeko 2020-11-24 21:14:14 Re: libpq Prepared Statement with dynamic IN operator