bytea type & nulls, Postgres

Posted by Thanatos on Stack Overflow See other posts from Stack Overflow or by Thanatos
Published on 2010-06-07T17:45:53Z Indexed on 2010/06/07 18:02 UTC
Read the original article Hit count: 261

Filed under:

I'm using a bytea type in PostgreSQL, which, to my understanding, contains just a series of bytes. However, I can't get it to play well with nulls. For example:

=# select length(E'aa\x00aa'::bytea);
 length
--------
      2
(1 row)

I was expecting 5. Also:

=# select md5(E'aa\x00aa'::bytea);
               md5
----------------------------------
 4124bc0a9335c27f086f24ba207a4912
(1 row)

That's the MD5 of "aa", not "aa\x00aa". Clearly, I'm Doing It Wrong, but I don't know what I'm doing wrong. I'm also on an older version of Postgres (8.1.11) for reasons outside of my control. (I'll see if this behaves the same on the latest Postgres as soon as I get home...)

© Stack Overflow or respective owner

Related posts about postgresql