From: | "Hugh Mandeville" <hughmandeville(at)hotmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Re: binary data |
Date: | 2001-06-21 21:29:41 |
Message-ID: | 9gtovc$mnr$1@news.tht.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
"Alex Pilosov" <alex(at)pilosoft(dot)com> wrote in message
news:Pine(dot)BSO(dot)4(dot)10(dot)10106201342060(dot)20262-100000(at)spider(dot)pilosoft(dot)com(dot)(dot)(dot)
> Yes, there is a binary datatype, called 'bytea', which can handle anything
> you can throw at it, including nulls.
>
> The rules for escaping things you want to throw at it are tricky though.
> (and same for unescaping things you get back from database).
i ended up having to use the C large object functions to write binary data.
i wasn't able to insert nulls using the INSERT command with psql, C or Perl.
what is the correct way to escape 0? \000 doesn't work for me.
i created a table with a 'bytea' column. i inserted data escaping out
special characters with their 3 digit octet.
everything inserts correctly except null (\000). data with null characters
inserted with no errors but doing a select for the value or for its size
came back incorrectly. it returns everything before the null character.
i tried inserting and selecting the data with psql and the C interface
(PQexec, PQgetvalue, PQgetlength).
here is a log from my psql session. the last insert i did 'null \000 null'
comes back as octet length 5 which is wrong, it should be 11.
test=# CREATE TABLE log (data bytea);
CREATE
test=# INSERT INTO log (data) VALUES ('plain text');
INSERT 61650 1
test=# INSERT INTO log (data) VALUES ('special chars \n \001 \002');
INSERT 61651 1
test=# INSERT INTO log (data) VALUES ('null \000 null');
INSERT 61652 1
test=# SELECT octet_length(data), data FROM log;
octet_length | data
--------------+------------------------------
10 | plain text
19 | special chars \012 \001 \002
5 | null
(3 rows)
> If you are using perl, use DBD::Pg version 1.00 or higher, it encapsulates
> it all transparently.
i also tried doing an insert and using quote() with perl (DBD::Pg v1.0)
$sql = "INSERT INTO log (data) VALUES (" . $dbh->quote($bindata) . ")";
it has the same problem when the data contains a null, perl returns
"DBD::Pg::st execute failed: ERROR: Unterminated quoted string at ..."
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2001-06-21 23:46:07 | Re: case, new column not found |
Previous Message | Mark Hamby | 2001-06-21 20:50:58 | RE: Select most recent record? |