Re: Strict-typing benefits/costs

From: Ken Johanson <pg-user(at)kensystem(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Strict-typing benefits/costs
Date: 2008-02-16 17:04:36
Message-ID: 47B717A4.1000206@kensystem.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Ken Johanson <pg-user(at)kensystem(dot)com> writes:
>> select 5<'6' -> true
>> select 5>'6' -> false
>> select 15<'60' -> true
>> select 15>'60' -> false
>
> These examples miss the point, because they'd give the same answer
> whether you think the values are text or integer. Consider instead
> these cases:
>
> regression=# select 7 > '60'; -- int > int
> ?column?
> ----------
> f
> (1 row)
>
> regression=# select '7' > '60'; -- text > text
> ?column?
> ----------
> t
> (1 row)
>
> regression=# select 7 > '08'; -- int > int
> ?column?
> ----------
> f
> (1 row)
>
> regression=# select '7' > '08'; -- text > text
> ?column?
> ----------
> t
> (1 row)
>
> All of a sudden it seems much more important to be clear about
> what data type is involved, no?

Agreed, so should we disallow 7 > '08'? Because that is (tell me if you
disagree), much more hazardous than allowing, say TRIM(7) or
POSITION('7' IN 7). Or for non-failfast comparison of two columns of
dissimilar types (say bigint, integer, real, char).

select 'ba'>'ab' -> true
select 'ab'>'ba' -> false
select '0.5'=.5 -> true (is char comparator or numeric to laymen?)
select '7a'<'070' -> true (is char comparator or numeric to laymen?)
select '7a'<70 -> failfast, good.

>
>> Numbers and datetime in sql have exactly prescribed standard char
>> representations (even if others dbs don't use them for datetimes).
>
> See the datestyle parameter before you maintain that Postgres
> should assume that.
>
>

I agree. Unless the date style is know to always be iso8601, which is
not true owed to datestyle. Unless sql spec allows for it, could this be
an argument for removing the datestyle implict (non-iso8601) feature?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2008-02-16 19:05:41 Re: SELECT CAST(123 AS char) -> 1
Previous Message Tom Lane 2008-02-16 16:47:20 Re: Strict-typing benefits/costs