تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
6564 أدوات العرض

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

الصورة الرمزية
إهمال
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.

أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

You were right it works now, thanks!

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مارس 15
8535
1
أبريل 24
1370
2
أبريل 21
5341
3
مايو 20
12765
1
فبراير 19
5795