pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Mail about typecast
6+ messages / 4 participants
[nested] [flat]

* Mail about typecast
@ 1999-06-14 15:33 Vikrant Rathore <vikrant@chemquick.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Vikrant Rathore @ 1999-06-14 15:33 UTC (permalink / raw)
  To: pgsql-sql

I want to do a following operation on the timespan

select overdue * date_part('epoch',usage)::float4 from indusevar;

where overdue is of type float4 and i want to typecast
date_part('epoch',usage) to float4 since dat_part(text,timespan) returns
a float8 type.
Whenever I try to typecast it gives an error 'function  dtof(float8)
does not exist'. Can anyone help me to solve the problem.
Thanks in advance for your valuable advice.
Waiting for a response.

Regards,
Vicky





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Mail about typecast
@ 1999-06-15 03:17 Vikrant Rathore <vikrant@chemquick.com>
  1999-06-15 12:42 ` Re: [SQL] Mail about typecast José Soares <jose@sferacarta.com>
  1999-06-15 13:39 ` Re: [SQL] Mail about typecast Tom Lane <tgl@sss.pgh.pa.us>
  1999-06-15 13:52 ` Re: [SQL] Mail about typecast Herouth Maoz <herouth@oumail.openu.ac.il>
  0 siblings, 3 replies; 6+ messages in thread

From: Vikrant Rathore @ 1999-06-15 03:17 UTC (permalink / raw)
  To: pgsql-sql

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.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [SQL] Mail about typecast
  1999-06-15 03:17 Mail about typecast Vikrant Rathore <vikrant@chemquick.com>
@ 1999-06-15 12:42 ` José Soares <jose@sferacarta.com>
  2 siblings, 0 replies; 6+ messages in thread

From: José Soares @ 1999-06-15 12:42 UTC (permalink / raw)
  To: vikrant@chemquick.com; +Cc: pgsql-sql



Vikrant Rathore ha scritto:

> 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.

Which version of PostgreSQL are you using?
This works for me. (v6.5)

hygea=> \df dtof
result|function|arguments|description
------+--------+---------+------------------------
float4|dtof    |float8   |convert float8 to float4
(1 row)

hygea=> select date_part('epoch','12 hours'::timespan)::float4;
float4
------
 43200
(1 row)

hygea=> select date_part('epoch','12 hours'::timespan);
date_part
---------
    43200
(1 row)

______________________________________________________________
PostgreSQL 6.5.0 on i586-pc-linux-gnu, compiled by gcc 2.7.2.3
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jose'

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [SQL] Mail about typecast
  1999-06-15 03:17 Mail about typecast Vikrant Rathore <vikrant@chemquick.com>
@ 1999-06-15 13:39 ` Tom Lane <tgl@sss.pgh.pa.us>
  2 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 1999-06-15 13:39 UTC (permalink / raw)
  To: vikrant@chemquick.com; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [SQL] Mail about typecast
  1999-06-15 03:17 Mail about typecast Vikrant Rathore <vikrant@chemquick.com>
@ 1999-06-15 13:52 ` Herouth Maoz <herouth@oumail.openu.ac.il>
  1999-06-15 14:07   ` Re: [SQL] Mail about typecast Tom Lane <tgl@sss.pgh.pa.us>
  2 siblings, 1 reply; 6+ messages in thread

From: Herouth Maoz @ 1999-06-15 13:52 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; vikrant@chemquick.com; +Cc: pgsql-sql

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





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [SQL] Mail about typecast
  1999-06-15 03:17 Mail about typecast Vikrant Rathore <vikrant@chemquick.com>
  1999-06-15 13:52 ` Re: [SQL] Mail about typecast Herouth Maoz <herouth@oumail.openu.ac.il>
@ 1999-06-15 14:07   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 1999-06-15 14:07 UTC (permalink / raw)
  To: Herouth Maoz <herouth@oumail.openu.ac.il>; +Cc: vikrant@chemquick.com; pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~1999-06-15 14:07 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-06-14 15:33 Mail about typecast Vikrant Rathore <vikrant@chemquick.com>
1999-06-15 03:17 Mail about typecast Vikrant Rathore <vikrant@chemquick.com>
1999-06-15 12:42 ` José Soares <jose@sferacarta.com>
1999-06-15 13:39 ` Tom Lane <tgl@sss.pgh.pa.us>
1999-06-15 13:52 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1999-06-15 14:07   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox