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) :)