Error on sql string with Postgres as DB and with AS clause into GROUP BY param

Issue #11 closed
created an issue

Hello, on my project I'm using django-easyfilters and I found an exception at the rendering of the widget.

I got the follow exception:

ProgrammingError: syntax error at or near "AS" LINE 1: ...RUNC('year', "my_table"."starting_date") AS easyfil... ^

This happen when the widget is rendering and into the query to get the date is added, inside the param of GROUP BY: , DATE_TRUNC('year', "my_table"."starting_date") AS easyfilter_date_alias

When i remove: DATE_TRUNC('year', "my_table"."starting_date") AS easyfilter_date_alias From the SQL string i don't have the exception.

My Postgres don't allow AS into the GROUP BY param.

I'm with: - "PostgreSQL 9.1.12 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.8.1-10ubuntu8) 4.8.1, 64-bit" - Django version 1.6.1 - django-easyfilters trunk version

Comments (2)

  1. Luke Plant repo owner

    I'm having trouble reproducing this at all.

    When I run the test suite, I test queries like this:

    SELECT easyfilter_date_alias, COUNT(easyfilter_date_alias) FROM
        (SELECT DATE_TRUNC('year', "tests_book"."date_published") as easyfilter_date_alias FROM "tests_book" WHERE ("tests_book"."date_published" < '1815-01-01'  AND "tests_book"."date_published" >= '1813-01-01' ) ORDER BY 1 ASC) subquery GROUP BY (easyfilter_date_alias) ORDER BY (easyfilter_date_alias);

    From above, and from the code, you can see it doesn't generate 'GROUP BY' clauses with an 'AS':

    ...rather, it just uses the alias name.

    To get close to debugging this, I'll need you to add an complete test case to the test suite - or at the very least, the complete SQL that is generated - you've only given me some snippets.

  2. Log in to comment