[Dbix-class] Why does this query not work?
Dennis Daupert
ddaupert at gmail.com
Wed Mar 9 22:49:18 GMT 2011
I'm trying to code a simple query in DBIC. I get an error,
and don't understand why. What am I doing wrong?
QUERY:
SELECT sym as stc, count(*) as stc_count
FROM i1tickets
GROUP BY stc
ORDER BY stc_count DESC;
CODE:
$i1_tic_rs
=3D $schema_pg->resultset('I1tickets')->search(
{},
{
select =3D> [
'sym',
{ count =3D> '*' },
],
as =3D> [qw/
stc
stc_count
/],
group_by =3D> [qw/ stc /],
order_by =3D> { -desc =3D> [qw/ stc_count /] },
}
);
ROW:
while ( $row =3D $i1_tic_rs->next ) {
$stc =3D $row->stc;
$stc_count =3D $row->stc_count;
....
ERROR:
DBIx::Class::ResultSet::next(): DBI Exception: DBD::Pg::st execute failed:
ERROR: column "stc_count" does not exist
LINE 1: ...OUNT( * ) FROM i1tickets me GROUP BY stc ORDER BY stc_count ...
^ [for
Statement "SELECT sym, COUNT( * ) FROM i1tickets me GROUP BY stc ORDER BY
stc_count DESC"]
I don't see the alias declarations in the error msg...
BTW, is there a DBIC helper tool you can feed an sql
query and have it spit out Perl code? I could use one ;-)
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110309/3e4=
975ac/attachment.htm
More information about the DBIx-Class
mailing list