Re: bytea internal encoding - Mailing list pgsql-general

From Ron Peterson
Subject Re: bytea internal encoding
Date
Msg-id 20041216051747.GA814@mtholyoke.edu
Whole thread Raw
In response to bytea internal encoding  (Ron Peterson <rpeterso@mtholyoke.edu>)
List pgsql-general
On Wed, Dec 15, 2004 at 11:08:29PM -0500, Ron Peterson wrote:

> How are bytea values encoded internally?
>
> Or maybe a better question would be what is the proper way to access
> bytea data from within a C function?  Are there utility functions for
> reading the bytea data as a stream of scalar values, for example?

If I do something like:

bytea* bindat = PG_GETARG_BYTEA_P(0);
int32 total_data_bytes = VARSIZE( bindat ) - VARHDRSZ;
char* test_cp = (char*)palloc( total_data_bytes );
memcpy( test_cp, VARDATA( bindat ), total_data_bytes );
fwrite( test_cp, 1, total_data_bytes, test_fp );

I get the exactly the same binary file out that I stuffed into
PostgreSQL by octal escaping it and doing an insert.  Am I asking for
trouble writing code like this?

--
Ron Peterson
Network & Systems Manager
Mount Holyoke College
http://www.mtholyoke.edu/~rpeterso

pgsql-general by date:

Previous
From: Frans
Date:
Subject: Aggregates not allowed in WHERE clause?
Next
From: Tom Lane
Date:
Subject: Re: Aggregates not allowed in WHERE clause?