Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Error in sql while using operator "in" and variable

By
DM
on 5/21/15, 8:22 AM 697 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

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.

DM
on 5/21/15, 10:19 AM
0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 5/21/15, 9:11 AM

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

1
DM
On 5/21/15, 11:13 AM

You were right it works now, thanks!

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/21/15, 8:22 AM
Seen: 697 times
Last updated: 10/23/15, 9:18 AM