From: | "Merlin Moncure" <mmoncure(at)gmail(dot)com> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
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:18:58 |
Message-ID: | b42b73150710111018o7bae97a9s3788702f8efa031c@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 10/10/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Merlin Moncure" <mmoncure(at)gmail(dot)com> writes:
> > I'm curious what's considered the best way to invoke PG_GETARG_BYTEA_P
> > in an SPI routine and properly check for null input in non 'strict'
> > routines. Right now, I'm looking at PG_GETARG_POINTER to check for
> > null value before using PG_GETARG_BYTEA_P to assign to the bytea
> > pointer.
>
> That would be entirely wrong. In a non-strict function, test
> PG_ARGISNULL(n) before attempting any variant of PG_GETARG(n).
> Grepping for PG_ARGISNULL will yield lots of examples.
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))
{
...I since found the place in the documentation which explains this
though, at the end of the portion describing the V1 calling
convention.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-10-11 17:48:10 | Re: XMIN semantic at peril ? |
Previous Message | Erik Jones | 2007-10-11 16:47:37 | Re: XMIN semantic at peril ? |