Re: Composite types as parameters

From: Elijah Stone <elronnd(at)elronnd(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Composite types as parameters
Date: 2021-06-27 02:01:47
Message-ID: 363ec928-b0b8-c1eb-2f88-47d43c18ba7@elronnd.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 26 Jun 2021, Tom Lane wrote:
> You probably would have better results from specifying the composite
> type explicitly in the query:
>
> PQexecParams("insert into sometable values($1::composite, ...);",
>
> I gather from the complaint that you're currently doing something that
> causes the Param to be typed as a generic "record", which is problematic
> since the record's details are not available from anyplace. But if you
> cast it directly to a named composite type, that should work.
>
> If it still doesn't work, please provide a more concrete example.

Thanks, unfortunately adding the explicit cast doesn't help. I've
attached a minimal runnable example.

I am serializing as a generic record, so it occurs to me that another
solution would be to use the actual type of the composite in question.
(Though it also seems to me that my code should work as-is.) Is there a
way to discover the OID of a composite type? And is the wire format the
same as for a generic record?

-E

Attachment Content-Type Size
demo.c text/plain 1.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Julien Rouhaud 2021-06-27 03:31:53 Re: [HACKERS] Preserving param location
Previous Message Michael Paquier 2021-06-27 01:43:00 Re: [PATCH] Make jsonapi usable from libpq