Thread: bug in working with TEXT constants ?

bug in working with TEXT constants ?

From
sad
Date:
Good day.

AFAIK PostgreSQL provides the type TEXT with 4-byte prefix length
which is distinct to C's zero-terminated  (char *)
That's very good.
Then I expect natural possibility to store texts having zero characters.

try
SELECT 'abc\0de';
SELECT length('abc\0de');
or insert such a value into another table and then select....

you'll see a classical result just like you are using (char *).
i suppose it is a little bug deep inside like using a memcpy() or such...

Am i wrong?



Re: bug in working with TEXT constants ?

From
Stephan Szabo
Date:
On Tue, 28 Oct 2003, sad wrote:

> Good day.
>
> AFAIK PostgreSQL provides the type TEXT with 4-byte prefix length
> which is distinct to C's zero-terminated  (char *)
> That's very good.
> Then I expect natural possibility to store texts having zero characters.

If you want to store zero characters (or binary data) you
probably want bytea not text.


Re: bug in working with TEXT constants ?

From
Tom Lane
Date:
sad <sad@bankir.ru> writes:
> Then I expect natural possibility to store texts having zero characters.

You expect wrong; we don't support embedded nulls in text values, nor in
literal strings.  You can store nulls in BYTEA fields, but you have to
use bytea's escaping conventions to represent the value in SQL commands,
eg, 'foo\\000bar'.
        regards, tom lane