Re: Sorting MySQL queries
| From: | Curt Zirzow | Date: | Mon, 06 Nov 2006 17:16:44 +0000 |
| Subject: | Re: Sorting MySQL queries | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244265@lists.php.net to get a copy of this message | ||
On 11/5/06, Roman Neuhauser <neuhauser@sigpipe.cz> wrote:
Thats rather nifty, i dont think you can do that with mysql, but you could achieve something close to that with a trigger for insert/update to apply the regex to a different field that is used for sorting. The other option would make a policy to put ", The" or ", A" at the end of the string a simple function to render the text without the comma at the end would be simple to do. CurtIf you used PostgreSQL I'd suggest a functional index and ordering on the function... Does MySQL have anything like this?CREATE FUNCTION fn(TEXT) RETURNS TEXT IMMUTABLE STRICT LANGUAGE SQL AS $$ SELECT regexp_replace($1, '^(?:(?:a|the)[[:space:]]+)', '', 'i'); $$;CREATE INDEX ON table(fn(subject));