question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

select(distinct=...) may produce faulty sql for sqlite

See original GitHub issue

This one works:

In [45]: db().select(db.player.country, distinct = True)
Out[45]: <Rows (40)>

In [46]: db._lastsql
Out[46]: 'SELECT DISTINCT player.country FROM player;'

But the other option given in the book does not:

In [47]: db().select(db.player.country, distinct = db.player.country)
OperationalError: near "ON": syntax error

In [48]: db._lastsql
Out[48]: 'SELECT DISTINCT ON (player.country) player.country FROM player;'

I didn’t test it with other DB engines since I don’t currently have one installed.

Related to https://github.com/web2py/web2py/issues/1129

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gi0barocommented, Apr 19, 2016

@niphlod Damn, I ended the refactoring and forgotten this. We should re-start a discussion. I vote for the SyntaxError on sqlite when using DISTINCT ON.

0reactions
niphlodcommented, Apr 20, 2016

start away, my previous semi-detailed comment pretty much lays every path that can be taken.

Read more comments on GitHub >

github_iconTop Results From Across the Web

select(distinct=...) may produce faulty sql for sqlite · Issue #1129
This one works: In [45]: db().select(db.player.country, distinct = True) Out[45]: In [46]: db._lastsql Out[46]: 'SELECT DISTINCT player.country FROM player ...
Read more >
Problem with sqlite want distinct attribute when creating view
I'm trying to create a view from different tables. One table contains attributes such as year, name, and country the second one contains ......
Read more >
SQLite SELECT DISTINCT - Removing Duplicate in Result ...
This tutorial shows you how to use SQLite SELECT DISTINCT clause to remove duplicate rows by applying the DISTINCT clause on one column...
Read more >
sqlite - Get distinct values through direct query of an index
I've never used SQLite so bear with me here. But it seems as if this problem is common among many RDBMS platforms. When...
Read more >
Distinguishing CREATE TABLE failure (already exists) from ...
Is there any good way to distinguish CREATE TABLE failure due to table already exists from other possible failures?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found