Re: DISTINCT with NULLs and INT fields

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: DISTINCT with NULLs and INT fields
Date: 2005-12-29 03:03:19
Message-ID: 3362.1135825399@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"George Pavlov" <gpavlov(at)mynewplace(dot)com> writes:
> the interesting thing here is that 4::int gets into a text
> field whereas 4::text does not get into an integer field. seems to me
> like there is an implicit int-to-text cast (without a symmetrical
> text-to-int one)

Yeah, there is. You can easily see the list of implicit casts for
yourself:

select castsource::regtype, casttarget::regtype from pg_cast
where castcontext = 'i' and castsource != casttarget;

There's 90 of them in current CVS tip, and most of 'em are unsurprising
within-type-category casts, such as implicit promotion of int to bigint.
However we have about a dozen implicit casts to text from the numeric
and datetime type categories. Personally I would dearly love to get
rid of these, because they are accidents waiting to happen (and they
do regularly bite people, see the mail list archives for evidence).
But it seems people expect to be able to do things like
number || ' string'
without explicitly casting the number to text.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2005-12-29 07:16:25 Re: constraint and ordered value
Previous Message Michael Fuhr 2005-12-29 02:48:16 Re: Cursors and recursion