Re: Storing images in PG? - Mailing list pgsql-general

From Joe Conway
Subject Re: Storing images in PG?
Date
Msg-id 027d01c12679$76bf9590$48d210ac@jecw2k1
Whole thread Raw
In response to RE: Storing images in PG?  ("Andrew Snow" <andrew@modulus.org>)
List pgsql-general
> Postgresl, in treating things as strings, handles \000 as NULL as an end
> of string.
>
>  select 'abc\000def' as hehehe;
>  hehehe
> --------
>  abc
> (1 row)
>

By the way, the '\000' string in the select statement above does get
converted to '\0' prior to byteain(), and that is precisely why the value
returned is truncated at that point. Take a look at the following snipit of
code:

<snip>
Datum
byteain(PG_FUNCTION_ARGS)
{
 char    *inputText = PG_GETARG_CSTRING(0);
 char    *tp;
 char    *rp;
 int   byte;
 bytea    *result;

 for (byte = 0, tp = inputText; *tp != '\0'; byte++)
</snip>

Notice that byteain() gives up as soon as it hits a '\0' in the input
string. So the '\\000' on the client end turns into '\000' by the time it
hits byteain(), and byteain converts it to a single character '\0'. Hope
this all makes sense.

-- Joe





pgsql-general by date:

Previous
From: Jeremy Hansen
Date:
Subject: race conditions in my sequences
Next
From: Jan Wieck
Date:
Subject: Re: Storing images in PG?