Re: Implementing an operator in C?

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Mario(dot)Weilguni(at)kpnqwest(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Implementing an operator in C?
Date: 2001-02-06 14:14:33
Message-ID: 3A8006C9.DBD99DDE@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Mario Weilguni wrote:
>
> Am Sonntag, 4. Februar 2001 20:12 schrieben Sie:
> > Mario Weilguni <mweilguni(at)sime(dot)com> writes:
> > > float8 num3 = numeric_float8(num1);
> >
> > That won't work in the brave new world of 7.1 :-(. You need to do
> > something like
> >
> > float8 num3 = DatumGetFloat8(DirectFunctionCall1(numeric_float8,
> > NumericGetDatum(num1)));
> >
> > Ugly, I know ... but we have to be rigidly careful about converting
> > values to Datum and back in order to avoid portability problems.
> >
> > A decent C compiler should've warned about type mismatches in your call,
> > BTW.
> >
> > regards, tom lane
>
> Thanks alot for the info, but the problem is elsewhere. Even a simple
> function like
> Datum
> nef(PG_FUNCTION_ARGS)
> {
> Numeric num1 = PG_GETARG_NUMERIC(0);
> PG_RETURN_BOOL(true);
> }
>
> will crash. The macro PG_GETARG_NUMERIC evaluates to:
> ((Numeric)pg_detoast_datum((struct varlena *) ((Pointer) ( (fcinfo->arg[0])))
> and this pg_detoast_datum will lead to a crash (SIGSEGV). So I think I must
> be doing something wrong here, isn't it?

Could be. What data type *is* the input argument? It had better be of
type "NUMERIC", and not of type "FLOAT8", which of course uses a
different accessor function...

- Thomas

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Myron Scott 2001-02-06 15:05:04 Re: Using Threads
Previous Message Thomas Lockhart 2001-02-06 14:02:49 Re: AW: timestamp in pg_dump