From: Alvaro Herrera <alvherre@commandprompt.com>
To: George Pavlov <gpavlov@mynewplace.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: DISTINCT with NULLs and INT fields
Date: Wed, 28 Dec 2005 18:24:02 -0300
Message-ID: <20051228212402.GC5231@surnet.cl> (raw)
In-Reply-To: <CCB89282FCE1024EA3DCE687A96A5164039EC5FE@ehost010-6.exch010.intermedia.net>
References: <CCB89282FCE1024EA3DCE687A96A5164039EC5FE@ehost010-6.exch010.intermedia.net>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: alvherre@commandprompt.com, gpavlov@mynewplace.com
Subject: Re: DISTINCT with NULLs and INT fields
In-Reply-To: <20051228212402.GC5231@surnet.cl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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