Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YVIbi-0004SC-IS for pgsql-odbc@arkaria.postgresql.org; Tue, 10 Mar 2015 11:45:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YVIbh-00067H-OK for pgsql-odbc@arkaria.postgresql.org; Tue, 10 Mar 2015 11:45:53 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YVIbg-00067A-Pb for pgsql-odbc@postgresql.org; Tue, 10 Mar 2015 11:45:52 +0000 Received: from vs17.mail.saunalahti.fi ([62.142.117.198]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YVIbc-0004VG-EK for pgsql-odbc@postgresql.org; Tue, 10 Mar 2015 11:45:50 +0000 Received: from vams (localhost [127.0.0.1]) by vs17.mail.saunalahti.fi (Postfix) with SMTP id 34E2D1000D1 for ; Tue, 10 Mar 2015 13:45:44 +0200 (EET) Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi [195.197.172.111]) by vs17.mail.saunalahti.fi (Postfix) with ESMTP id 1CC291000BA for ; Tue, 10 Mar 2015 13:45:44 +0200 (EET) Received: from it-eo3.infotripla.fi (unknown [193.185.91.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by gw03.mail.saunalahti.fi (Postfix) with ESMTPSA id 0887220057 for ; Tue, 10 Mar 2015 13:45:42 +0200 (EET) Message-ID: <54FED966.7070705@infotripla.fi> Date: Tue, 10 Mar 2015 13:45:42 +0200 From: =?UTF-8?B?RXNhIMOWc3RyaW5n?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: pgsql-odbc@postgresql.org Subject: Writing binary data (bytea) fails in PostgreSQL 9.3, succesful in PostgreSQL 9.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org Dear list, I am trying to write binary data to bytea column in PostgreSQL 9.3 with=20 unixODBC, but the process fails. Symptom is, that some data is escaped=20 in bytea column after write, and the overall length of binary data is=20 thus increased during write,resulting corrupted data. Same code works=20 perfectly with PostgreSQL 9.0, length of binary data is preserved. Exact versions of servers are PostreSQL 9.3.6 and 9.0.3. Versions of drivers used (rpm packages, up to date Fedora 20): ----8<---- postgresql-odbc-09.03.0400-3.fc20.x86_64 perl-DBD-ODBC-1.50-3.fc20.x86_64 unixODBC-2.3.2-4.fc20.x86_64 ----8<---- I have tried to isolate the problem, and wrote a perl script to be able=20 to recreate the problem. Please see the details below. Should I use some extra configuration parameters to force binary data=20 write for postgres 9.3, or is there something else I'm doing wrong? Perl DBD::Pg -driver (not odbc) seems to handle binary data write=20 correctly (code not provided here), but odbc is really THE option for=20 me, since I am using odbc functionality from R, using RODBC. This code=20 excerpt is simply an isolation of problems I faced in RODBC. Details follow: * perl script to reconstruct the problem in postgresql 9.0 and=20 postgresql 9.3 databases. ----8<---- #!/usr/bin/perl -w use strict; use DBI qw(:sql_types); # postgresql 9.0 my $data_source90 =3D q/dbi:ODBC:pg90/; # postgresql 9.3 my $data_source93 =3D q/dbi:ODBC:pg93/; # Connect to the data source and get a handle for that connection. my $dbh90 =3D DBI->connect($data_source90) or die "Can't connect to $data_source90: $DBI::errstr"; my $dbh93 =3D DBI->connect($data_source93) or die "Can't connect to $data_source93: $DBI::errstr"; # read file my $buffer =3D ""; #my $infile =3D "read_me_in.png"; my $infile =3D "read_me_in.wld"; open (INFILE, "<", $infile) or die "Not able to open the file. \n"; binmode (INFILE); my $file; #Read file in 64K blocks while ( (read (INFILE, $buffer, 65536)) !=3D 0 ) { $file .=3D $buffer; } close (INFILE) or die "Not able to close the file: $infile \n"; print length($file), "\n"; my $sth90 =3D $dbh90->prepare("INSERT INTO data_queue (data) VALUES (?)") or die "Can't prepare statement: $DBI::errstr"; $sth90->bind_param(1, $file, {TYPE =3D> SQL_BINARY}); $sth90->execute(); my $sth93 =3D $dbh93->prepare("INSERT INTO data_queue (data) VALUES (?)") or die "Can't prepare statement: $DBI::errstr"; $sth93->bind_param(1, $file, {TYPE =3D> SQL_BINARY}); $sth93->execute(); # Disconnect the database from the database handle. $dbh90->disconnect; $dbh93->disconnect; ----8<---- Excerpt from psql, after data is input to database: postgres 9.3 (binary write failed) ----8<---- data_static=3D> select length(data) from data_queue ; length -------- 134 (1 row) data_static=3D> select encode(data,'escape') from data_queue ; encode ---------------------------------------------------------------------------= -------------------------------------------------------------------------- 1802\\0568571428571\\0120\\0560000000000\\0120\\0560000000000\\012\\05517= 42\\0568571428573\\01298901\\0564285714286\\0127779128\\0565714286640\\012 (1 row) data_static=3D> \d data_queue Table "public.data_queue" Column | Type | Modifiers --------------------------+--------------------------+----------- id | bigint | data | bytea | ----8<---- postgres 9.0 (all OK) ----8<---- data_static=3D> select encode(data,'escape') from data_queue ; encode -------------------- 1802.8571428571 + 0.0000000000 + 0.0000000000 + -1742.8571428573 + 98901.4285714286 + 7779128.5714286640+ (1 row) data_static=3D> \d data_queue Table "public.data_queue" Column | Type | Modifiers --------------------------+--------------------------+----------- id | bigint | data | bytea | data_static=3D> select length(data) from data_queue ; length -------- 95 (1 row) ----8<---- Best regards, M.Sc Esa =C3=96string Data scientist Infotripla Oy Tampere, Finland --=20 Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc