Re: Re: binary data

Поиск
Список
Период
Сортировка
От Hugh Mandeville
Тема Re: Re: binary data
Дата
Msg-id 9gtovc$mnr$1@news.tht.net
обсуждение исходный текст
Ответ на Re: Re: binary data  (Alex Pilosov <alex@pilosoft.com>)
Ответы Re: Re: Re: binary data  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
"Alex Pilosov" <alex@pilosoft.com> wrote in message
news:Pine.BSO.4.10.10106201342060.20262-100000@spider.pilosoft.com...
> 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 ..."







В списке pgsql-sql по дате отправления:

Предыдущее
От: Roelof Sondaar
Дата:
Сообщение: Re: set datestyle to European PROBLEM
Следующее
От: "Ari Nepon"
Дата:
Сообщение: Help with a double left join