Re: Cast to integer

From: Robert Osowiecki <robson(at)cavern(dot)pl>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Cast to integer
Date: 2005-10-06 07:36:59
Message-ID: 4344D41B.7030700@cavern.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

A. Kretschmer wrote:

>am 05.10.2005, um 15:08:33 +0200 mailte Robert Osowiecki folgendes:
>
>
>>Hello!
>>
>>Anyone could explain to me, why cast(3.33 to int) works (from float, I
>>suppose) but cast('3.33' to int) (from text) does not? And what if I
>>create a cast for that: is it possibly dangerous?
>>
>>
>
>test=# select '3.33'::float::int;
> int4
>------
> 3
>(1 row)
>
>
>
Let me explain better. I encountered this problem when I tried to write
general unit-calculation (from kilograms to punds, for example) function
operating on any arithmetic datatype: with float and numeric it went all
ok, but failed with integer on "return $result" with error "invalid
input syntax for integer". My function internally operated on numeric
type. I wrote a wrap-around for integer, because I've been afraid, that
changing "text to integer" cast (or input function, whatever it is)
could damage something important.

R.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tzvetan Tzankov 2005-10-06 08:37:35 Re: PostgreSQL 8.1 vs. MySQL 5.0?
Previous Message Dann Corbit 2005-10-06 06:24:11 Re: PostgreSQL 8.1 vs. MySQL 5.0?