Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite doesn't like double parens #396

Closed
jhorman opened this issue Jul 18, 2014 · 2 comments
Closed

SQLite doesn't like double parens #396

jhorman opened this issue Jul 18, 2014 · 2 comments

Comments

@jhorman
Copy link
Contributor

jhorman commented Jul 18, 2014

This sample program shows the problem

from peewee import Model
from peewee import fn
from peewee import SqliteDatabase

db = SqliteDatabase(':memory:')

class User(Model):
    class Meta:
        db = db

User.create_table()

list(User.select().where(fn.Exists(User.select(User.id))))

Func always wraps the nodes in parens: https:/coleifer/peewee/blob/2.2.5/peewee.py#L1141

And nested selects are always in parens: https:/coleifer/peewee/blob/2.2.5/peewee.py#L1174

One approach might just be in the isinstance(node, Func) detect if the sql to wrap already startswith('(') and endswith(')'), but maybe there is something more clever.

@coleifer
Copy link
Owner

SELECT t1."id"
FROM "users" AS t1 
WHERE Exists((SELECT t2."id" FROM "users" AS t2))

@jhorman
Copy link
Contributor Author

jhorman commented Jul 18, 2014

Nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants