C-language stored function and float4 type

Поиск
Список
Период
Сортировка
Искать

C-language stored function and float4 type

От:
whiplash <whiplash@bss.org.ua>
Дата:
Hello! I have C-language stored function like this:

#include 
#include 

#ifdef PG_MODULE_MAGIC
     PG_MODULE_MAGIC;
#endif

PG_FUNCTION_INFO_V1(testfunc);

Datum testfunc(PG_FUNCTION_ARGS)
{
     float4 x = PG_GETARG_FLOAT4(0);
     float4 y = PG_GETARG_FLOAT4(1);

     PG_RETURN_FLOAT4(x + y);
}

CREATE FUNCTION testfunc ( x real, y real )
RETURNS real AS
'testfunc'
LANGUAGE C STRICT;

If i use this function (SELECT testfunc ( 0.1, 0.2 )) I get result with 
type "double precision". I tried used float4 but the result was the 
same. What is wrong?

Re: C-language stored function and float4 type

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
whiplash  writes:
> Hello! I have C-language stored function like this:
> CREATE FUNCTION testfunc ( x real, y real )
> RETURNS real AS
> 'testfunc'
> LANGUAGE C STRICT;

> If i use this function (SELECT testfunc ( 0.1, 0.2 )) I get result with 
> type "double precision".

What's your basis for asserting that?  The function is clearly defined
to return float4.

			regards, tom lane

Re: C-language stored function and float4 type

От:
sachin kotwal <kotsachin@gmail.com>
Дата:
How you checked result type?
Can you explain in details?



-----
Thanks and Regards,

Sachin Kotwal
NTT-DATA-OSS Center (Pune)
--
View this message in context: http://postgresql.1045698.n5.nabble.com/C-language-stored-function-and-float4-type-tp5773493p5774840.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Re: C-language stored function and float4 type

От:
whiplash <whiplash@bss.org.ua>
Дата:
Sorry, I created an overloaded function and forgot about it.
> whiplash  writes:
>> Hello! I have C-language stored function like this:
>> CREATE FUNCTION testfunc ( x real, y real )
>> RETURNS real AS
>> 'testfunc'
>> LANGUAGE C STRICT;
>> If i use this function (SELECT testfunc ( 0.1, 0.2 )) I get result with
>> type "double precision".
> What's your basis for asserting that?  The function is clearly defined
> to return float4.
>
> 			regards, tom lane
>


FAQ