C Language Stored Procedure Returning No Data

From: bfraci(at)aol(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: C Language Stored Procedure Returning No Data
Date: 2006-02-01 17:56:30
Message-ID: 8C7F56FF6FA1531-13B0-2A40@FWM-D45.sysops.aol.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


We have a Java client that is using JDBC to communicate with the Postgres database. We have a stored procedure, foo, that is written in C which returns a byte array (bytea) to the Java client. This function takes in a couple of integers and based upon their values can return a byte array or no data. From a C stored procedure, how can I tell Postgres to pass on to the Java client that there is No Data? A zero length byte array or a null value is not the same as No Data.

Thanks for any help that you can give.

The stored procedure is defined as:

CREATE OR REPLACE FUNCTION foo(int8, int8)
RETURNS bytea AS 'foolib.so', 'foo'
LANGUAGE C STRICT;

The C function foo looks like:

PG_FUNCTION_INFO_V1(foo);
Datum foo ( PG_FUNCTION_ARGS)
{
int64 int1 = PG_GETARG_INT64(0);
int64 int2 = PG_GETARG_INT64(1);
bytea *data = NULL;

if ( int1 > 12345 ) {
/* Somehow indicate that there is no data */
/* Doing the following does not tell Java that there is no data; it gets a null value */
PG_RETURN_NULL();
}

/* Some processing */

PG_RETURN_BYTEA_P( data );
}


Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ed L. 2006-02-01 18:05:32 Re: pg 8.1.2 ERROR: direct correlated subquery unsupported as initplan
Previous Message Bruce Momjian 2006-02-01 17:22:49 Re: Gotcha's in copying data between servers via file copy