Re: C functions and int8?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-sql(at)hub(dot)org
Subject: Re: C functions and int8?
Date: 2000-09-22 02:06:27
Message-ID: 25782.969588387@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Forest Wilkinson <fspam(at)home(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message root 2000-09-22 13:58:56 how to store a query, that results in a table
Previous Message Forest Wilkinson 2000-09-22 00:35:27 Re: C functions and int8?