From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Felix(dot)徐 <ygnhzeus(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to convert a double value to a numeric datum type in pgsql? |
Date: | 2014-02-24 07:44:26 |
Message-ID: | CAFj8pRDQY8JoXiwNQGG7jtVs2ZvrNxZQkFXcDYLMDxWSX2HRkg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2014-02-24 8:42 GMT+01:00 Felix.徐 <ygnhzeus(at)gmail(dot)com>:
> Thanks , I find another function called OidInputFunctionCall which can
> automatically generate a datum from a string for any data type, but seems
> it is not recommended in the comments.
>
it is little bit different - and it needs a second conversion - double ->
string
Regards
Pavel
>
>
> 2014-02-24 15:32 GMT+08:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>
>
>> hello
>>
>> you have to look to postgresql/src/backend/utils/adt/numeric.c functions
>> -
>>
>> then you can call float8_numeric
>>
>> Numeric result = DatumGetNumeric(DirectFunctionCall1(float8_numeric,
>> Float8GetDatum(dx));
>>
>> regards
>>
>> Pavel
>>
>>
>> 2014-02-24 7:45 GMT+01:00 Felix.徐 <ygnhzeus(at)gmail(dot)com>:
>>
>>> Hi all,
>>> I'm talking about the source code of pgsql and I want to know how the
>>> typing system works in pgsql.
>>> A few functions can help us do the type conversion, for example:
>>>
>>> Int32GetDatum -- convert a integer to a datum
>>> Float8GetDatum -- convert double to a datum
>>> cstring_to_text -- convert a string to a text
>>> ...
>>>
>>> but there are a lot of types in pgsql,how to choose the corresponding
>>> function? or is there a more automatic way to do the type conversion(raw
>>> chars to a datum, suppose I have the corresponding Form_pg_type instance)?
>>>
>>> I ask this question because I don't know how to convert a double value
>>> to a numeric datum(the field's type is numeric(10,2)), pg_type shows that
>>> numeric's typlen is -1 whose length is variable thus Float8GetDatum is not
>>> working..
>>>
>>>
>>>
>>>
>>>
>>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Magnus Hagander | 2014-02-24 15:27:06 | Re: stand by is starting until I do some work in the primary |
Previous Message | Pavel Stehule | 2014-02-24 07:32:34 | Re: How to convert a double value to a numeric datum type in pgsql? |