Re: 38.10.6. Composite-Type Arguments C-language function code demo works for int, but not for numeric.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: 38.10.6. Composite-Type Arguments C-language function code demo works for int, but not for numeric.
Date: 2023-02-01 15:05:44
Message-ID: 1369043.1675263944@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

jian he <jian(dot)universality(at)gmail(dot)com> writes:
> column "salary" int data type works fine. But it does not work if the
> "salary" column data type is numeric.

Your problem is that numeric is not a primitive C type:

> PG_RETURN_BOOL(DatumGetNumericCopy(salary) > limit);

That is comparing two pointers-to-numerics, not the values of
the numerics. You'd need to invoke numeric_cmp() if you
want a sensible result.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Wim Bertels 2023-02-01 15:21:05 Re: Best Open Source OS for Postgresql
Previous Message Mateusz Henicz 2023-02-01 14:37:19 Re: pg_rewind and replication user