Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
3 Antwoorden
6549 Weergaven

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

Beste antwoord

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
Annuleer
Auteur Beste antwoord

You were right it works now, thanks!

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
mrt. 15
8531
1
apr. 24
1368
2
apr. 21
5338
3
mei 20
12757
1
feb. 19
5782