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

Sqlalchemy expression IN is not working #171

Open
ReshnaNP opened this issue Jan 15, 2018 · 7 comments
Open

Sqlalchemy expression IN is not working #171

ReshnaNP opened this issue Jan 15, 2018 · 7 comments
Labels

Comments

@ReshnaNP
Copy link

I have tried the below example from the documentation, but it is not working.
Example
http://127.0.0.1:5000/people?where={"firstname":"in(\"(\'John\',\'Fred\'\"))"}

Please help me to understand, how to use IN sqlalchemy expression?

@amoyiki
Copy link

amoyiki commented Jan 23, 2018

I have same problem
if i used http://127.0.0.1:5000/biddings?where={"id":"in(\"(10,12\"))"}
raw sql like

SELECT ...
FROM tabel
WHERE table.id = %s [<sqlalchemy.sql.elements.BinaryExpression object at 0x04CFA790>]

I used http://127.0.0.1:5000/people?where={"id":"in(\"(10,12)\")"}
raw sql like

SELECT ...
FROM tabel
WHERE table.id in %s [<sqlalchemy.sql.elements.BinaryExpression object at 0x04CFA790>]

but catch a error

sqlalchemy.exc.ProgrammingError: (_mysql_exceptions.ProgrammingError) 
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''(10,12)'

print sql

SELECT ...
FROM tabel
WHERE table.id  IN '(10,12)'

'(10,12)' has single quote
Thanks a bunch for any help! ;)

@amoyiki
Copy link

amoyiki commented Jan 23, 2018

OK, I know, that documentation example is missing
http://127.0.0.1:5000/people?where={"id":"in([10,12])"}
The above can work.
Am I right? @dkellner

@ReshnaNP
Copy link
Author

Hi amoyiki,
Thanks for the reply :)
I have tried , http://127.0.0.1:5000/people?where={"id":"in([10,12])"}.
It does not seems to work (tried for PostgreSQL database server ).

@amoyiki
Copy link

amoyiki commented Jan 23, 2018

yes, use "in([10,12])" not work, my mistake,sorry

@amoyiki
Copy link

amoyiki commented Jan 23, 2018

@ReshnaNP i think you can use
where={"or_": [{"id":"__eq__(10)"}, {"id": "__eq__(12)"}]}
instead of in

@amoyiki
Copy link

amoyiki commented Jan 26, 2018

@ReshnaNP
?where={"user_id":[4,5]} can work
you can see tests/sql.py

@dkellner dkellner added the bug label Feb 11, 2018
@LaQuay
Copy link
Contributor

LaQuay commented Nov 6, 2018

Hi, i'm facing the same issue.

Here I add my scenario, the syntax follows the documentation.

param = {
    "title": "in(\"('NAME_1', 'NAME_2')\")"
}
url = "/my_endpoint/?where=" + json.dumps(param)
api_client.get(url)

Is generating this SQLExpression, which is not correct.

WHERE my_model.title in '(''NAME_1'', ''NAME_2'')'

This should generate something like:

WHERE my_model.title in ('NAME_1', 'NAME_2')

Also, as @amoyiki said, this is working

param = {
    "title": ['NAME_1', 'NAME_2']
}
url = "/my_endpoint/?where=" + json.dumps(param)
api_client.get(url)

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

No branches or pull requests

4 participants