NpgsqlBinaryImporter fails with incorrect binary data format

See original GitHub issue

I’m trying to do a binary copy from Windows to postgres on ubuntu. After writing several rows of data, the command is closed and an exception is thrown. This is the relevant Npgsql stack trace:

Npgsql.NpgsqlException (0x80004005): 22P03: incorrect binary data format
   at Npgsql.NpgsqlConnector.DoReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage, Boolean isPrependedMessage)
   at Npgsql.NpgsqlConnector.ReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage)
   at Npgsql.NpgsqlConnector.ReadExpecting[T]()
   at Npgsql.NpgsqlBinaryImporter.Close()

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mkedocommented, Mar 12, 2016

Postgresql docs says

the binary format is very data type specific; for example it will not work to output binary data from a smallint column and read it into an integer column, even though that would work fine in text format.

That is likely your case. Your postgresql log should give you more information on which column is the culprit.

Had this issue today. My problem was that I passed a System.DateTime value to the NpgsqlBinaryImporter.Write() method for a date column, which then was sent to postgres as a 8 byte value, but postgres requires 4 byte values for date columns. It worked after I explicitly passed NpgsqlDbType as the second argument binImporter.Write(value, NpgsqlDbType.Date);

0reactions
rojicommented, Mar 21, 2016

@mkedo thanks for the example, I wasn’t aware that PostgreSQL implicitly converts byte array input into geometry in this way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

psycopg2: inexplicable 'DataError: incorrect binary data ...
I'm using a COPY ... WITH BINARY query. The tables I'm copying, only contain integers and only go into tables containing integers.
Read more >
ERROR: "incorrect binary data format in bind parameter" while ...
This issue occurs while fetching RAW data from Oracle and inserting data into the Postgre data type bit. The session runs without any...
Read more >
ERROR: incorrect binary data format in bind parameter 2
machine works. Are you using x86_64 binary? If so, can you please try this suggestion? - What is "indexer -S" output?
Read more >
inserting into "date" field returns error (COPY/BINARY)
WITH BINARY command. All field types are working as expected in PG9.2, except "date": ERROR: incorrect binary data format
Read more >
Prisma Postgres $queryRaw butchering numeric types
Running on node 16.11.1 on Ubuntu/WSL. const [{ id }] = await db.$queryRaw`select ${1.5}::int id` // Raw query failed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found