Re: Storing images in PG?

From: "Joe Conway" <joseph(dot)conway(at)home(dot)com>
To: "Andrew Snow" <andrew(at)modulus(dot)org>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Storing images in PG?
Date: 2001-08-16 17:32:44
Message-ID: 027d01c12679$76bf9590$48d210ac@jecw2k1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-08-16 17:32:51 Re: Roll Back dont roll back counters
Previous Message Joe Conway 2001-08-16 17:09:27 Re: Storing images in PG?