Re: preferred way to use PG_GETARG_BYTEA_P in SPI

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
Cc: "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: preferred way to use PG_GETARG_BYTEA_P in SPI
Date: 2007-10-11 17:52:08
Message-ID: 2580.1192125128@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Merlin Moncure" <mmoncure(at)gmail(dot)com> writes:
> well, there aren't all that many examples in contrib, and some of the
> ones that are there look like this (edited) from tsearch2:

> Datum
> rewrite_accum(PG_FUNCTION_ARGS)
> {
> QUERYTYPE *acc = (QUERYTYPE *) PG_GETARG_POINTER(0);
> ArrayType *qa = (ArrayType *)
> DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1)));
> if (acc == NULL || PG_ARGISNULL(0))
> {

That might be safe but it sure looks like bad practice to me.
In particular I think it's unwise to assume that the Datum value
for a null will always be zero.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris Travers 2007-10-11 18:04:52 Feature request: SSL Client Cert Authentication
Previous Message Tom Lane 2007-10-11 17:48:10 Re: XMIN semantic at peril ?