Re: Selecting a constant question: A summary

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Chuck McDevitt <cmcdevitt(at)greenplum(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Hammond <andrew(dot)george(dot)hammond(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org, Dann Corbit <DCorbit(at)connx(dot)com>, Larry McGhaw <lmcghaw(at)connx(dot)com>
Subject: Re: Selecting a constant question: A summary
Date: 2007-06-13 07:03:52
Message-ID: 20070613070352.GB10351@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jun 13, 2007 at 02:12:37AM -0400, Chuck McDevitt wrote:
> So, where x = '(1,2)' might be legal for comparing to x, but a field of
> type varchar(5) might not be, as in where x = y, where y is type
> varchar(5) containing '(1,2)'.

Normally, just about every type can be converted to or from text. So if
postgres converted to varchar first you have problems with the
statement x='const' where x is type "foo". It's now ambiguous since you
either convert x to varchar or the constant to "foo". Instead, postgres
marks the constant as unknown and now it always gets converted because
nothing can convert to unknown.

Thus far this system has worked excellently, though not perfectly
obviously. It matches people's expectations well, which is the most
important part.

> I find PostgreSQL's handling of this strange, as I come from systems
> where 'xxx' is either a varchar or char type, in all contexts, and
> implicit casts handle any needed conversions.
> But now I understand why it does things this way.

User-defined types makes for lots of interesting choices, but they are
by far the most powerful feature of postgres and we don't want to mess
with that.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2007-06-13 09:25:35 EXPLAIN omits schema?
Previous Message ITAGAKI Takahiro 2007-06-13 06:28:51 DROP TABLE and autovacuum