eve-sqlalchemy icon indicating copy to clipboard operation
eve-sqlalchemy copied to clipboard

Sqlalchemy expression IN is not working

Open ReshnaNP opened this issue 7 years ago • 7 comments

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?

ReshnaNP avatar Jan 15 '18 04:01 ReshnaNP

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 avatar Jan 23 '18 01:01 amoyiki

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

amoyiki avatar Jan 23 '18 03:01 amoyiki

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 ).

ReshnaNP avatar Jan 23 '18 05:01 ReshnaNP

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

amoyiki avatar Jan 23 '18 06:01 amoyiki

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

amoyiki avatar Jan 23 '18 07:01 amoyiki

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

amoyiki avatar Jan 26 '18 07:01 amoyiki

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)

LaQuay avatar Nov 06 '18 11:11 LaQuay