Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Using Arel::Nodes::DistinctOn in select with PostgreSQL generates syntax error #302
The following select:
results in a syntax error when run:
It works without that comma:
This happens using Arel 184.108.40.20640414130214 and Postgres 220.127.116.11 (14).
Sorry if this is just because I'm not using it right. I haven't found any documentation for using Arel::Nodes::DistinctOn but thought it would be nice to use Arel to do the DISTINCT ON instead of using a string.
After a little investigation, I confirmed that this is just because I was using it wrong.
By including it in the
As far as I can tell, there is no way to use
select_statement = Arel::Nodes::SelectStatement.new select_statement.cores.first.set_quantifier = Arel::Nodes::DistinctOn.new(Arel::Table.new(:countries)[:id]) select_statement.cores.first.projections << Arel.star select_statement.to_sql # => "SELECT DISTINCT ON ( \"countries\".\"id\" ) *"
This is not the most convenient but it works.
I think it would be nice to be able to set the DISTINCT ON in a similar way to setting a normal DISTINCT. Something like:
table = Arel::Table.new(:users) table.project(Arel.star).distinct_on(table[:id]).to_sql # => "SELECT DISTINCT ON ( \"users\".\"id\" ) * FROM \"users\""
I will add a pull request that implements this.