> > Which dies because $count is assigned zero, making the statement > > evaluate false. > > Whoops, careless copy/paste. That's fixed in SVN now.
Great, thanks very much! > > > 2. If I am counting objects related by a many-to-many where the > > mapping table has a multi-valued primary key, the query generated is > > something like > > > > SELECT > > COUNT(DISTINCT t1.a_id, t1.b_id) > > FROM > > a_b_map t1 > > JOIN b t2 ON (t1.b_id = t2.id) > > WHERE > > t1.a_id=xxx > > > > But Postgres says > > > > ERROR: function count(integer, integer) does not exist at character 9 > > Hm, what is the correct SQL in that case for Postgres? Postgres defines the function separately from count(*): count(expression) number of input values for which the value of expression is not null In this case I would write SELECT COUNT(coalesce(t1.a_id, t1.b_id)) Which would count the number of rows that have at least one non-null value in the primary keys. Is that enough, or do we need to be explicit and only count rows where every piece of the primary key is not null? I think that would look something like SELECT COUNT(t1.a_id IS NOT NULL AND t1.b_id IS NOT NULL) Cheers, Derek ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object