[Tutor] OT SQL (but through Python...)

Liam Clarke cyresse at gmail.com
Fri Feb 25 10:24:56 CET 2005


Hi, 

Hope I don't annoy anyone by asking this here, if I do, let me know. 

When you're doing a SQL select statement, what would be better? Say
you're searching by name, should I do -
j = cx.execute
j('select * from foo where first == %s and last == %s') % (a,b)
q = cx.fetchall()
if not q: 
    j('select * from foo where first like %s%% and last like %s%%') % (a,b)

or just use 

j('select * from foo where first like %s%% and last like %s%%') % (a,b)

straight off the bat?

The first method gives me direct match, and searches for alternatives
if none are found,
the second may not give me a direct match if there is one. 

i.e 

first             last

Tim           Johns
Timothy    Johnston

the 1st method will find the 1st row for a='Tim' b = 'Johns's, but the
2nd method will find both.

I'm asking more from a user perspective really, would the quicker
action of the first outweigh the inconstant UI resulting from a
search?

I ask because a database I use heavily at work obviously uses 'like
%s%', which is great for the lazy typers such as myself, but sometime
I wish it would go directly to the only legitimate match, when it has
x number of precisely matching fields.

S'pose it's one of those better/best practises things. I remember
reading somewhere regarding Linux this pithy saying - 'The problem
(with KDE/Gnome etc. ) is that programmers can't design UI.' After my
experiences with KDE, I would tend to agree.


Regards, 

Liam Clarke
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list