Types info on binary copy

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Types info on binary copy
Date: 2021-01-05 12:09:57
Message-ID: CA+mi_8ama_9uM0CbO3q2xHpMuAcNH7-DQkkZKGHq=Xu95aJJmw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2021-01-05 12:18:43 Re: Cirrus CI (Windows help wanted)
Previous Message Andrew Dunstan 2021-01-05 11:45:28 Re: Context diffs