postgres `IN` query value substitution for lists is incorrect
See original GitHub issueIn [2]: frappe.db.sql("select name from `tabItem` where name in %s", (["abc", "xyz"],), debug=1)
select name from "tabItem" where name in ARRAY['abc','xyz']
Syntax error in query:
select name from "tabItem" where name in %s
---------------------------------------------------------------------------
SyntaxError Traceback (most recent call last)
File <ipython-input-2-6d9b73d925f2>:1, in <cell line: 1>()
----> 1 frappe.db.sql("select name from `tabItem` where name in %s", (["abc", "xyz"],), debug=1)
File ~/benches/pg/apps/frappe/frappe/database/postgres/database.py:121, in PostgresDatabase.sql(self, query, values, *args, **kwargs)
120 def sql(self, query, values=(), *args, **kwargs):
--> 121 return super(PostgresDatabase, self).sql(
122 modify_query(query), modify_values(values), *args, **kwargs
123 )
File ~/benches/pg/apps/frappe/frappe/database/database.py:185, in Database.sql(self, query, values, as_dict, as_list, formatted, debug, ignore_ddl, as_utf8, auto_commit, update, explain, run, pluck)
182 if not isinstance(values, (dict, tuple, list)):
183 values = (values,)
--> 185 self._cursor.execute(query, values)
187 if frappe.flags.in_migrate:
188 self.log_touched_tables(query, values)
SyntaxError: syntax error at or near "ARRAY"
LINE 1: select name from "tabItem" where name in ARRAY['abc','xyz']
^
Hint: List values don’t work but tuple values do.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
7.8. WITH Queries (Common Table Expressions) - PostgreSQL
Recursive Query Evaluation So long as the working table is not empty, repeat these steps: Evaluate the recursive term, substituting the current contents...
Read more >Documentation: 15: SELECT - PostgreSQL
When GROUP BY is present, or any aggregate functions are present, it is not valid for the SELECT list expressions to refer to...
Read more >Documentation: 15: 4.2. Value Expressions - PostgreSQL
Value expressions are used in a variety of contexts, such as in the target list of the SELECT command, as new column values...
Read more >Documentation: 15: 43.5. Basic Statements - PostgreSQL
PL/pgSQL variables will be substituted into the query just as described above, and the plan is cached in the same way. Also, the...
Read more >Documentation: 15: 9.7. Pattern Matching - PostgreSQL
operators, functions are available to extract or replace matching substrings ... Table 9.16 lists the available operators for pattern matching using POSIX ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
(hoping we don’t use it in future as well 📿 🙏 )
we could cast it to tuple as a quick fix 😛
probably here: https://github.com/frappe/frappe/blob/8c6d266fad4a99103a45125987ff21d260457a3a/frappe/database/postgres/database.py#L405-L430