Cdbcommandbuilder::createcountcommand() Fails With Postgresql

Although this is more of a Postgres related question I am giving it a shot.

I have constructed a criteria object which I use with the CDbCommandBuilder’s createCountCommand and createFindCommand and that works OK.

The problem appeared with the count command on a table with composite primary key.

The postgres error is the following:

SQL: SQLSTATE[42883]: Undefined function: 7 ERROR: function count(character varying, integer) does not exist LINE 1: SELECT COUNT(DISTINCT "t".id, "t".library_id) FROM "ab_colle... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

Any help or suggestion is appreciated.

After checking out the source I think you need to set the select property of CDbCriteria explicitly. There are some conditions detecting if it starts with a ‘count’ string.

The query produced by the framework looks specific to MySQL, so it’s a bug and should be reported on Github.

I thought as well because I am sure that it works with MySQL. I will do so.