Re: Prefered Types - Mailing list pgsql-hackers

From Jim Nasby
Subject Re: Prefered Types
Date
Msg-id 86171A1C-33F3-4B4F-9356-4CBA17C8989E@nasby.net
Whole thread Raw
In response to Re: Prefered Types  (Зотов Роман <zotov@oe-it.ru>)
Responses Re: Prefered Types  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On May 4, 2011, at 12:00 AM, Зотов Роман wrote:
>>> F(smallint)
>>> F(integer)
>>> but call like F(float)
>>> i wouldn`t like to fail it.
>> I think this particular example would be a mistake, because that cast
>> would be lossy, so you want to invoke it only when the user explicitely
>> selects it.  The other way around would be fine, I think, that is,
>> F(float)
>> F(float8)
>> and the call is F(int)
> As i think i not must write function with Float, String, and many other arg when my function have INT arg... and if
callerwouln`t think about types he cant use your strong types 
> why it not must work like as assignment??? why implicit and assignment is different???
> I know only implicit and explicit casts and i think imlicit=asssign

I was ready to educate Зотов on why that was a bad idea until I read...

> Yes, but while you think what update table1 set IntField = FloatField is valid
> but Select FuncWithIntArg(FloatArg) is not valid
> you have no problems in current solution, because it works same :)

Sure enough, this works: UPDATE ... SET int_field = ( SELECT float_field FROM ... );

Which begs the question... why do we allow on assignment casting of a float to an int? I would think that should be
explicitonly... 

If we are going to allow assignment casting of float to int, then I'm hard-pressed to see why we wouldn't allow you to
callan int function with a float value, assuming there wasn't a more suitable cast available. 
--
Jim C. Nasby, Database Architect                   jim@nasby.net
512.569.9461 (cell)                         http://jim.nasby.net




pgsql-hackers by date:

Previous
From: Jim Nasby
Date:
Subject: Re: branching for 9.2devel
Next
From: Tom Lane
Date:
Subject: Re: Prefered Types