converting numeric to string in postgres code

Started by Szymon Guzover 12 years ago3 messages
#1Szymon Guz
mabewlun@gmail.com

Hi,
while hacking on some Postgres code I've found a problem.

I need to convert numeric to string. I've got datum with numeric inside, so
I'm getting it like:

Numeric *numeric = DatumGetNumeric(d);

but later I need to have string (most probably: const char *). I've found a
couple of different ways for doing that, but I'm not aware of side effects.

Which function/macro should I use?

thanks,
Szymon

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Szymon Guz (#1)
Re: converting numeric to string in postgres code

Hello

2013/5/28 Szymon Guz <mabewlun@gmail.com>:

Hi,
while hacking on some Postgres code I've found a problem.

I need to convert numeric to string. I've got datum with numeric inside, so
I'm getting it like:

Numeric *numeric = DatumGetNumeric(d);

but later I need to have string (most probably: const char *). I've found a
couple of different ways for doing that, but I'm not aware of side effects.

Which function/macro should I use?

There is a numeric_out function, you can use it or look on their source code

result = DatumGetCString(DirectFunctionCall1(numeric_out, d));

Regards

Pavel

thanks,
Szymon

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Szymon Guz
mabewlun@gmail.com
In reply to: Pavel Stehule (#2)
Re: converting numeric to string in postgres code

On 28 May 2013 12:07, Pavel Stehule <pavel.stehule@gmail.com> wrote:

Hello

2013/5/28 Szymon Guz <mabewlun@gmail.com>:

Hi,
while hacking on some Postgres code I've found a problem.

I need to convert numeric to string. I've got datum with numeric inside,

so

I'm getting it like:

Numeric *numeric = DatumGetNumeric(d);

but later I need to have string (most probably: const char *). I've

found a

couple of different ways for doing that, but I'm not aware of side

effects.

Which function/macro should I use?

There is a numeric_out function, you can use it or look on their source
code

result = DatumGetCString(DirectFunctionCall1(numeric_out, d));

Thanks.