Thread: Mail about typecast
Dear friends, I want to run a query : vikrant=> select date_part('epoch','12 hours'::timespan)::float4; It returns a error message ERROR: function dtof(float8) does not exist But i want to use typecast since the result of this query will be used to update a field of type float4. I have checked the pg_proc system table it has a function dtof with float8 as argument i have checked the list of functions also and 'dtof(float8)' is shown in that list also. can anyone solve this problem. I can solve the problem by using a c program but i want to know when the function dtof(float8) is there in pg_proc table then why it is not doing a typecasting. Thanks in advance for your kind suggestion. Thanks & regards, Vikrant.
<p>Vikrant Rathore ha scritto: <blockquote type="CITE">Dear friends, <p> I want to run a query : <p>vikrant=> selectdate_part('epoch','12 hours'::timespan)::float4; <br />It returns a error message <br />ERROR: function dtof(float8)does not exist <p>But i want to use typecast since the result of this query will be used <br />to update a fieldof type float4. <p>I have checked the pg_proc system table it has a function dtof with <br />float8 as argument i havechecked the list of functions also and <br />'dtof(float8)' is shown in that list also. <br />can anyone solve this problem.I can solve the problem by using a c <br />program but i want to know when the function dtof(float8) is there in<br />pg_proc table then why it is not doing a typecasting. <br />Thanks in advance for your kind suggestion. <p>Thanks& regards, <br /><tt>Vikrant.</tt></blockquote><tt>Which version of PostgreSQL are you using?</tt><br /><tt>Thisworks for me. (v6.5)</tt><tt></tt><p><tt>hygea=> \df dtof</tt><br /><tt>result|function|arguments|description</tt><br/><tt>------+--------+---------+------------------------</tt><br /><tt>float4|dtof |float8 |convert float8 to float4</tt><br /><tt>(1 row)</tt><tt></tt><p><tt>hygea=> select date_part('epoch','12hours'::timespan)::float4;</tt><br /><tt>float4</tt><br /><tt>------</tt><br /><tt> 43200</tt><br /><tt>(1row)</tt><tt></tt><p><tt>hygea=> select date_part('epoch','12 hours'::timespan);</tt><br /><tt>date_part</tt><br/><tt>---------</tt><br /><tt> 43200</tt><br /><tt>(1 row)</tt><tt></tt><p>______________________________________________________________<br />PostgreSQL 6.5.0 on i586-pc-linux-gnu,compiled by gcc 2.7.2.3 <br />^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <br />Jose'<br />
Vikrant Rathore <vikrant@chemquick.com> writes: > select date_part('epoch','12 hours'::timespan)::float4; > ERROR: function dtof(float8) does not exist What Postgres version are you using? The above query appears to work fine in both 6.4.2 and 6.5. I'm guessing you are getting bit by some bug in an older release ... If you don't want to update, you might also try the variant forms select float4(date_part('epoch','12 hours'::timespan)); select date_part('epoch','12 hours'::timespan) AS float4; regards, tom lane
At 16:39 +0300 on 15/06/1999, Tom Lane wrote: > select date_part('epoch','12 hours'::timespan) AS float4; Probably missing a CAST keyword here, isn't it? Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma
Herouth Maoz <herouth@oumail.openu.ac.il> writes: > At 16:39 +0300 on 15/06/1999, Tom Lane wrote: >> select date_part('epoch','12 hours'::timespan) AS float4; > Probably missing a CAST keyword here, isn't it? My mistake, this should have been select CAST (date_part('epoch','12 hours'::timespan) AS float4); (the parens are required too). The first way just relabels the output column, it doesn't actually change the datatype :-( regards, tom lane