Note that there are some explanatory texts on larger screens.

plurals
  1. POPostgreSQL bytea binary data inserting
    primarykey
    data
    text
    <p>Faced the following problem: inserting some binary data from the App to "bytea" field in our PostgreSQL 9.2 DB, we found out, that its length is doubled. The App is written in C++ and uses SQL API library to access Postgres. Reference to official doc: <a href="http://www.sqlapi.com/HowTo/blobs.html" rel="nofollow">http://www.sqlapi.com/HowTo/blobs.html</a></p> <p>Saying that data length is doubled means, that before insert command int the app we have: sContent.length() = 19 meanwhile in postgres we get: select length(bindata) = 38, bit_length( bindata ) = 304 from binpacket</p> <p>In C++ App we do:</p> <pre><code>SAString sContent = SomeFunctionConvertsByteArrayToSAString(bindata); cmd.Param("bindata").setAsLargeBinary() = sContent; //SA_dtLongBinary &lt;=&gt; BYTEA //watch: sContent.length() = 19 cmd.Execute(); </code></pre> <p>and have field length doubled in postgres (select length(bindata) = 38 ).</p> <p>I wrote some simple Python3 script, that inserts binary data from file to the database:</p> <pre><code>bindataStream = open('C:\\Temp\\bin.dat', 'rb').read() cursor.execute("INSERT INTO binpacket( bindata ) VALUES (%s)", (psycopg2.Binary(bindataStream ),)) </code></pre> <p>and the length of the data inserted is equal to the source binary data file.</p> <p>That leads me to the conclusion, that it is possible to insert binary data to Postgres 9 without having its length(size) doubled. But is it possible when the data source is a bytearray?</p> <p>Please, help to find an correct solution how to insert bytea binary data to Postgres. The explanations of the situation described would be appreciated too.</p> <p>Best regards, Anthony</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload