Re: converting datum to numeric

Lists: pgsql-hackers
From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: converting datum to numeric
Date: 2013-06-25 06:32:10
Message-ID: CAFjNrYv7_bBWHz8cAXAmeLGw9zJoiWqVp2W8BU4Tz5ivGxeuWQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,
I've got a couple of questions.

I was using numeric_out like this:

DatumGetCString(DirectFunctionCall1(numeric_out, d));

Why do I have to use DirectFunctionCall1 instead of calling numeric_out?

I was suggested to use numeric_send instead of numeric_out, however when
changing the function names in the above example, the whole expression
returns 8. Always 8. I check with:

char *x = DatumGetCString(DirectFunctionCall1(numeric_send, d));
PLy_elog(NOTICE, x).

And my main question: is there any documentation about those internal
functions, which use and when etc?

thanks
Szymon


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Szymon Guz <mabewlun(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: converting datum to numeric
Date: 2013-06-25 06:51:33
Message-ID: CAFj8pRAJjQOiZjRwL-5dB5h9E2Ede3bqmNPFn3YWjCMaMQxCNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2013/6/25 Szymon Guz <mabewlun(at)gmail(dot)com>:
> Hi,
> I've got a couple of questions.
>
> I was using numeric_out like this:
>
> DatumGetCString(DirectFunctionCall1(numeric_out, d));
>
> Why do I have to use DirectFunctionCall1 instead of calling numeric_out?

numeric_out functions doesn't use C calling convention - it use own
convention for support NULL values and some other informations.
DirectFunctionCall1 is simple function that transform C like call to
PostgreSQL call. You can do it directly, but you have to prepare
necessary structures.

>
>
> I was suggested to use numeric_send instead of numeric_out, however when
> changing the function names in the above example, the whole expression
> returns 8. Always 8. I check with:
>
> char *x = DatumGetCString(DirectFunctionCall1(numeric_send, d));
> PLy_elog(NOTICE, x).
>

"send" functions are used for binary protocol - so it is nonsense.

>
> And my main question: is there any documentation about those internal
> functions, which use and when etc?

source code :( and http://www.postgresql.org/docs/9.2/static/xfunc-c.html

src/backend/utils/atd/* is very useful and contains lot of materials for study

some examples of usage you can find in contrib examples

http://www.postgresql.org/docs/9.2/static/extend.html

Regards

Pavel

>
> thanks
> Szymon


From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: converting datum to numeric
Date: 2013-06-25 07:04:38
Message-ID: CAFjNrYsLOLjhbfQj5GXj+nqowXyWhebEQgcbap3ZGc-n0Qh=qg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 25 June 2013 08:51, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:

> Hello
>
> 2013/6/25 Szymon Guz <mabewlun(at)gmail(dot)com>:
> > Hi,
> > I've got a couple of questions.
> >
> > I was using numeric_out like this:
> >
> > DatumGetCString(DirectFunctionCall1(numeric_out, d));
> >
> > Why do I have to use DirectFunctionCall1 instead of calling numeric_out?
>
> numeric_out functions doesn't use C calling convention - it use own
> convention for support NULL values and some other informations.
> DirectFunctionCall1 is simple function that transform C like call to
> PostgreSQL call. You can do it directly, but you have to prepare
> necessary structures.
>
> >
> >
> > I was suggested to use numeric_send instead of numeric_out, however when
> > changing the function names in the above example, the whole expression
> > returns 8. Always 8. I check with:
> >
> > char *x = DatumGetCString(DirectFunctionCall1(numeric_send, d));
> > PLy_elog(NOTICE, x).
> >
>
> "send" functions are used for binary protocol - so it is nonsense.
>
>
>
Hi,
thanks for the information. So I will leave speeding it up for this moment.

thanks,
Szymon