Re: bytea internal encoding

From: Ron Peterson <rpeterso(at)mtholyoke(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: bytea internal encoding
Date: 2004-12-16 05:17:47
Message-ID: 20041216051747.GA814@mtholyoke.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-12-16 05:17:49 Re: Aggregates not allowed in WHERE clause?
Previous Message Frans 2004-12-16 05:02:34 Aggregates not allowed in WHERE clause?