From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-sql@hub.org
Subject: Re: C functions and int8?
Date: Thu, 21 Sep 2000 22:06:27 -0400
Message-ID: <25782.969588387@sss.pgh.pa.us> (raw)
In-Reply-To: <67alssorhjla484lck04khhju83h6g4aji@4ax.com>
References: <g7gjssk7jo2rq208b3a7usml6gffntt8vo@4ax.com>
<Pine.LNX.3.96.1000921103030.6462C-100000@ara.zf.jcu.cz>
<67alssorhjla484lck04khhju83h6g4aji@4ax.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgsql-sql@hub.org
Subject: Re: C functions and int8?
In-Reply-To: <25782.969588387@sss.pgh.pa.us>
References: <g7gjssk7jo2rq208b3a7usml6gffntt8vo@4ax.com> <Pine.LNX.3.96.1000921103030.6462C-100000@ara.zf.jcu.cz> <67alssorhjla484lck04khhju83h6g4aji@4ax.com> <25782.969588387@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox