On Wed, May 12, 2004 at 05:37:49PM -0700, Keith Herold wrote:
> In MS SQL 2000, through the query analyzer
> 
>    SELECT '500' = 500
> 
> returns 500 .
> 
>    SELECT 500 = '500'
> 
> returns 
>       Server: Msg 170, Level 15, State 1, Line 1
>       Line 1: Incorrect syntax near '='.

Well that's sure inordinately stupid behavior.  The test "A = B"
should give the same result as "B = A", at least!

In Oracle 8.1.7.4, string '5' does equal integer 5, but you seem to
have to ask it via a case statement:

  SQL> select 5 = 5 from dual; 
  ERROR at line 1: 
  ORA-00923: FROM keyword not found where expected 
   
  SQL> select  case when 5 = '5' then 1 else 0 end as bool  from dual; 
        BOOL 
  ---------- 
           1 
   
  SQL> select  case when '5' = 5 then 1 else 0 end as bool  from dual; 
        BOOL 
  ---------- 
           1 

> > But if that is the case, then clearly, '500' != 500.  So
> > unless somebody can come up with a better idea, SQLite
> > version 3.0 will return "0" for the following:
> > 
> >     SELECT '500'=500;
> > 
> > On the other hand, the following two statements will return
> > "1" (or true):
> > 
> >     SELECT '500'+0=500;
> >     SELECT '500'=(500||'');

That sounds ok to me.  Wouldn't it be clearer to have explicit cast
statements though, rather than doing weird no-ops like "||''" solely
to force a type conversion?

Also, since you're introducing manifest typing, it would probably be
very handy to have good boolean tests both for "is X currently of type
Y?" and "CAN X be of type Y?".  E.g., "CAN this thing be an integer?",
where by "can" I mean, "Is it currently an integer, or if it is
currently stored as a some other type, can it be LOSSLESSLY converted
to an integer?"

Some languages (e.g., S-Plus), make the latter oddly difficult.  (Not
THAT difficult; in S you can write that "can be integer" test in 5
lines, but those 5 lines are also somewhat easy to get wrong.)  I
think that in any system where objects can automatically change type,
both the those sorts of "can be" boolean tests should also be built
in.

-- 
Andrew Piskorski <[EMAIL PROTECTED]>
http://www.piskorski.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to