Re: DISTINCT with NULLs and INT fields - Mailing list pgsql-sql

From Alvaro Herrera
Subject Re: DISTINCT with NULLs and INT fields
Date
Msg-id 20051228212402.GC5231@surnet.cl
Whole thread Raw
In response to Re: DISTINCT with NULLs and INT fields  ("George Pavlov" <gpavlov@mynewplace.com>)
List pgsql-sql
George Pavlov wrote:

> test=# insert into foo values (4::int,4::int);
> INSERT 0 1
> test=# insert into foo values (4::text,4::text);
> ERROR:  column "b" is of type integer but expression is of type text
> HINT:  You will need to rewrite or cast the expression.
> test=# insert into foo values (cast(4 as int),cast(4 as int));
> INSERT 0 1
> test=# insert into foo values (cast(4 as text),cast(4 as text));
> ERROR:  column "b" is of type integer but expression is of type text
> HINT:  You will need to rewrite or cast the expression.

The last sentence (and the second one as well -- they are exactly
equivalent) exemplifies that there isn't an implicit typecase from text
to integer.  If you use single quotes instead of an explicit cast, the
literal is assumed to be of type "unknown", which _can_ be casted
automatically to integer.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


pgsql-sql by date:

Previous
From: "George Pavlov"
Date:
Subject: Re: DISTINCT with NULLs and INT fields
Next
From: Collin Peters
Date:
Subject: Help with simple query