Re: Check that numeric is zero

Поиск
Список
Период
Сортировка
От Andrew Gierth
Тема Re: Check that numeric is zero
Дата
Msg-id 878re1b1i3.fsf@news-spur.riddles.org.uk
обсуждение исходный текст
Ответ на Check that numeric is zero  (Gabriel Furstenheim Milerud <furstenheim@gmail.com>)
Список pgsql-general
>>>>> "Gabriel" == Gabriel Furstenheim Milerud <furstenheim@gmail.com> writes:

 Gabriel> Hi,

 Gabriel> I'm writing a Postgres native extension and I would like to
 Gabriel> check that a numeric is zero.

 Gabriel> My problem is that all exported methods like numeric_eq or
 Gabriel> numeric_sign require me to have a numeric to start with, and
 Gabriel> const_zero is not exported in numeric.c.

Currently the easiest and most portable way to get a numeric constant is
to call int4_numeric or int8_numeric via DirectFunctionCall; if you
don't care about versions older than pg14 there's also int64_to_numeric
which can be called directly from C.

    Datum zero_num = DirectFunctionCall1(int4_numeric, Int32GetDatum(0));

(remember that this will be allocated in the current memory context; if
you want to keep a copy long-term, you'd want to datumCopy it somewhere
else.)

-- 
Andrew (irc:RhodiumToad)



В списке pgsql-general по дате отправления:

Предыдущее
От: Thomas Munro
Дата:
Сообщение: Re: "PANIC: could not open critical system index 2662" - twice
Следующее
От: Jeffrey Walton
Дата:
Сообщение: Re: "PANIC: could not open critical system index 2662" - twice