-
-
Save eMerzh/d83a9c5436d7cb8cebec to your computer and use it in GitHub Desktop.
"Real" world example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION normalize(to_handle varchar) RETURNS varchar STRICT | |
AS $$ | |
BEGIN | |
return lower(regexp_replace(handle,'[^[:alnum:]]','', 'g')); | |
END; | |
$$ LANGUAGE plpgsql IMMUTABLE; | |
CREATE TABLE taxonomy ( id integer, name varchar, name_normalized varchar); | |
/** A trigger that does taxonomy.name_normalized := normalize(name); on insert and update; ***/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** search for Taxon **/ | |
$sth = $dbh->prepare("SELECT id, name | |
FROM taxonomy | |
WHERE name_normalized like normalize(?) || '%' "); | |
$sth->bindValue(1, $_POST['name'], PDO::PARAM_STR); | |
$sth->execute(); | |
$result = $sth->fetch(PDO::FETCH_ASSOC); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment