On Tue, Oct 27, 2009 at 04:07:37PM -0700, Darren Duncan scratched on the wall:
> Jay A. Kreibich wrote:
> > On Tue, Oct 27, 2009 at 04:15:57PM +0000, Tom Sillence scratched on the 
> > wall:
> >> because I really want to write neat queries like:
> >>
> >> select col1 is col2 from table
> > 
> >   Are you sure?  You just want a result set of true/false values?
> 
> There's nothing wrong with that. 

  True, it is valid SQL, it just (by itself) produces a result with
  questionable informational value.  With this query you have a list
  of true/false values, but you don't have any way to match those
  values up to the rows or data that produced them.

> Booleans are values like anything else,

  Actually they're not.  SQLite doesn't have Booleans, so this
  technically returns a column of integer values.  Just a long string
  of 1s and 0s.

> one should be able to store them as field values and return them in rowsets. 

  Yes, but just because you can do something doesn't mean it has a
  meaningful result.  The issue is not the usefulness of logic values,
  which is beyond question.  The issue is the usefulness and
  correctness of the query.

  If I saw this, I would expect that the programmer really meant
  something like "select col1 from table t where col1 is col2".
  At least then, when you have an implied "true", you know what row
  it is referring too.
  
  If for some reason you need to know both the trues and the falses,
  I'd expect a "select col1, col1 is col2 from..." or even "select
  col1, col1 is col2, col2 from...".  At least those queries allow you
  to put the logic value into some context.

  About the only reason I can think of to return the logic value, but
  no context for it, is if you're going to count them... and there are
  better/easier ways to do that in SQL.

  Or, even more likely, I'm reading too deeply into a greatly
  over-simplified example.



  From a style point, putting conditionals into the SELECT clause,
  rather than a WHERE or HAVING clause (or JOIN, or...), is kind of
  like putting an assignment in an "if" or "while" statement in C--
  although there are legit reasons to do it, most of the time it is
  in error and most programmers (and syntax checkers!) have trained
  themselves to raise an eyebrow whenever they see it.  Even if it
  might be correct, one usually stops and asks, "Are you sure?"

  If the answer is, "yes," then no worries (other than, perhaps,
  commenting or refactoring the code to avoid having every other
  developer that looks at that line take the time to ask and answer
  the same question).

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Our opponent is an alien starship packed with atomic bombs.  We have
 a protractor."   "I'll go home and see if I can scrounge up a ruler
 and a piece of string."  --from Anathem by Neal Stephenson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to