This question has been flagged
3 Replies
5256 Views

Hello odoo community Im just wondering whats wrong in this sql statement while using operator "in" and  variable from odoo.

Code Example:

sql="select sum(debit-credit) from account_account_period_sum where period_id in ({0}) and account_id = {1}".format (','.join(map(str,per_ids)), account_id)

When im trying to install module im getting :

ProgrammingError: syntax error at or near ")"

LINE 1: ...om account_account_period_sum where period_id in () and acco...

it seems like variable didnt get past when in ()

Thank you

Avatar
Discard
ok i did a test
per_ids2=[1,2,3]
sql="select sum(debit-credit) from account_account_period_sum where period_id in ({0}) and account_id = {1}".format (per_ids2, account_id)
and i got
ProgrammingError: syntax error at or near "["
LINE 1: ...om account_account_period_sum where period_id in ([1, 2, 3])...

On 21 May 2015 at 14:11, Pawan <pawanmisra.2008@gmail.com> wrote:

A new answer for Error in sql while using operator "in" and variable has been posted. Click here to access the post.

--
Pawan
Sent by Odoo S.A. using Odoo about Forum Post Error in sql while using operator "in" and variable



--

Darius Martinkus | Zeraxis Limited
E: darius.martinkus@zeraxis.com
M: 07450292546 | T: 020 8253 8015

This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of Zeraxis Limited. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this email is strictly prohibited. If you have received this email in error please contact the sender.

Best Answer

Hi Darius,

While using 'in' in sql statement you should have a 'list' like (1,2,3.....) to select data from.
like "select sum(debit-credit) from account_account_period_sum where period in (list of period_id values seperated by ,(comma))"

I think the data returning from '[','.join(map(str,per_ids))]' statement is not in correct format, please check the data returned.

 Thanks

Pawan

Avatar
Discard
Author Best Answer

You were right it works now, thanks!

Avatar
Discard