Re: C functions and int8? - Mailing list pgsql-sql

From Tom Lane
Subject Re: C functions and int8?
Date
Msg-id 25782.969588387@sss.pgh.pa.us
Whole thread Raw
In response to Re: C functions and int8?  (Forest Wilkinson <fspam@home.com>)
List pgsql-sql
Forest Wilkinson <fspam@home.com> writes:
> That's an int8 meaning "eight bit integer".  I want to work with an int8
> meaning "64 bit integer", as described in the docs:
> http://www.postgresql.org/users-lounge/docs/7.0/user/datatype.htm#AEN942
> So how do I return one of these suckers from a C function?

Emulate the code in src/backend/utils/adt/int8.c.

Currently this involves palloc'ing an int8, setting it, and returning
a pointer to it.  For instance, int8 addition is

int64 *
int8pl(int64 *val1, int64 *val2)
{   int64       *result = palloc(sizeof(int64));
   if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))       return NULL;
   *result = *val1 + *val2;
   return result;
}


In 7.1 it'll be a lot cleaner (IMNSHO anyway ;-)):

Datum
int8pl(PG_FUNCTION_ARGS)
{   int64        val1 = PG_GETARG_INT64(0);   int64        val2 = PG_GETARG_INT64(1);
   PG_RETURN_INT64(val1 + val2);
}

which actually does about the same things under the hood, but you
don't have to sully your hands with 'em ...
        regards, tom lane


pgsql-sql by date:

Previous
From: Forest Wilkinson
Date:
Subject: Re: C functions and int8?
Next
From: root
Date:
Subject: how to store a query, that results in a table