I was playing with cake and postgresql when I decided I needed to do a search. Sure a classic ‘%’ search would have been sufficient, but we all know I love using regular expressions in sql. Well come to find out it doesn’t seem that CakePHP likes PostgreSQL’s syntax when using its native conditions, so this didn’t work:
'conditions'=>array(
"Table.field ~*"=>$my_param
)
And neither did this:
'conditions'=>array(
"Table.field ~* ?"=>$my_param
)
I ended up having to create an array entry without a key at all, which is scary, but I knew for a fact that my sql parameter was only [a-zA-Z0-9]. Here’s what worked for me:
'conditions'=>array(
"Table.field ~* '$my_param'"
)
Bascially this told cake that this is the exact query condition I want to use without any parameters. Take it and like it! The docs read that it supports REGEX key word but we all know thats MySQL only (since you read my previous posts) :)
Related posts:


2 Responses
sam
01|Feb|2010 1Im intrigued by your decision to run postgresql over mysql. Do you have any reasoning behind this decision?
trent
02|Feb|2010 2Some reason it has always interested me. It seems to be a very capable database and at this point who knows what the future brings for mysql. I have been playing with it for about a year now and haven’t had the first complaint from the start.
Leave a reply