Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Backslash and Underscore problem with DBI and PostgreSQL.

by mpeppler (Vicar)
on Jun 21, 2004 at 07:15 UTC ( #368382=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Backslash and Underscore problem with DBI and PostgreSQL.
in thread Backslash and Underscore problem with DBI and PostgreSQL.

Is this fast:
select ... from .. where lower(username) = lower(?)
This may or may not be fast - it depends on how the query engine runs, and whether the optimizer can use an index when you apply a function on a column. It may work fine with Postgres, but I know that Sybase will not generate a good query plan with such a query.

BTW - If you use "LIKE ..." you can normally escape any potential wildcard characters yourself. Sybase uses square brackets to do the escaping (and can use alternate escape characters as well), so that you could write:

SELECT ... FROM ... where foo like ? ESCAPE '\'
and then pass "foo\_" as the search parameter and not get wildcard expansion on the underscore. Check the Postgres docs for similar functionality.

Michael


Comment on Re^3: Backslash and Underscore problem with DBI and PostgreSQL.
Select or Download Code
Re^4: Backslash and Underscore problem with DBI and PostgreSQL.
by ctilmes (Priest) on Jun 21, 2004 at 11:44 UTC
    This may or may not be fast - it depends on how the query engine runs, and whether the optimizer can use an index when you apply a function on a column.

    Probably premature optimization unless there are a lot of users, but PostgreSQL support indexes on expressions:
    http://www.postgresql.org/docs/7.4/interactive/indexes-expressional.html.

    As always, "explain" can be used to examine the optimizer's query plan.

Re^4: Backslash and Underscore problem with DBI and PostgreSQL.
by Seumas (Curate) on Jun 21, 2004 at 23:58 UTC
    I didn't expect lower() to have much of a speed impact and the query plan shows that the difference between doing a straight '=' or '~~*' and lower() is only 44msec versus 54msec.

    My indexes are pretty tight and it's a well (and often) maintained database. With millions of records, it has to be. :)

    The reason I didn't use LIKE is that I'm trying to allow users to create usernames that contain any characters they want without having to manually escape dozens of special characters myself.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://368382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-12-26 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls