Types info on binary copy - Mailing list pgsql-hackers

From Daniele Varrazzo
Subject Types info on binary copy
Date
Msg-id CA+mi_8ama_9uM0CbO3q2xHpMuAcNH7-DQkkZKGHq=Xu95aJJmw@mail.gmail.com
Whole thread Raw
Responses Re: Types info on binary copy  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello,

The PGresult structure returned on COPY ... FROM provides a handful of
information (https://www.postgresql.org/docs/13/libpq-copy.html):
number of fields expected and whether they are binary or not.

However it doesn't provide the types expected. For binary copy the
exact type is important: playing with it, it seems that no cast
whatsoever is applied and the errors reported are relatively low
level. For instance, passing an int4 value to an int8 field causes a
"protocol_violation: insufficient data left in message"; the other way
around is greeted with "invalid_binary_representation: incorrect
binary data format".

Naively, it would seem that once a "COPY ... FROM STDIN" is executed
successfully, the server has a pretty good idea of what data types it
is expecting. I'm wondering: is it absurd to ask for this info to be
returned as RowDescription and to be exposed by the libpq PQftype()?

Cheers

-- Daniele



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Context diffs
Next
From: Andrew Dunstan
Date:
Subject: Re: Cirrus CI (Windows help wanted)