Odoo Help


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.


problem with sql query writting

on 7/3/13, 5:29 AM 1,308 views

i am new to openerp. m trying to extract data of one table copy it into another and display the same but unable to perform this task please go through my code below and tell me where am doing mistake. i have already gone through the documentation.

class course_ba(osv.osv):
    _description="BA details"

  def course_ba(self, cr,uid,ids,name,reg_no,dob,sem,fees):            
    sql ='''select name,reg_no,dob,sem,fees into course_ba
             from student
             where  course = "BA" 
    res = cr.fetchall()
    return res

_columns = {
    'reg_no':fields.char('Reg_no', size=255),


when 'def course_ba' function is called???

Ghanshyam Prajapati
on 7/3/13, 7:07 AM

do you get any error messages when clicking on the button/link which executes course_ba.course_ba?

on 7/3/13, 10:36 AM

no i dont get any errors but sql is not working

on 7/4/13, 8:12 AM


| 5 4 7
Baarn, Netherlands
On 7/3/13, 10:46 AM

There is an issue with your SQL-query:

sql ='''select name,reg_no,dob,sem,fees into course_ba
         from student
         where  course = "BA" 

It looks like you want to get some content from the table student (which is NOT prefixed, are you sure you can read it like this?).

According to the documentation from postgresql:

SELECT INTO creates a new table and fills it with data computed by a query. The data is not returned to the client, as it is with a normal SELECT. The new table's columns have the names and data types associated with the output columns of the SELECT.

You want to return the data (given your code: return res), so try:

def copy_into_course_ba(self, cr,uid,ids,name,reg_no,dob,sem,fees):            
    sql ="select name, reg_no, dob, sem, fees from student  where  course = 'BA' "
    res = cr.fetchall()
#if you want to store the data into another table
result_ids = []
for r in res:
   new_id = self.create(cr, uid, {

return True #or return result_ids, or return len(result_ids), depending on what the result needs to be

Hiral Patel (hip)

--Hiral Patel (hip)--
Tiny ERP Pvt Ltd
| 2 1 5
--Hiral Patel (hip)--

Hiral Patel (hip)
On 7/3/13, 9:26 AM

Hello, Use self.cr.execute(sql) & self.cr.fetchall()

tried but no use

on 7/4/13, 8:12 AM

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

3 follower(s)


Asked: 7/3/13, 5:29 AM
Seen: 1308 times
Last updated: 3/16/15, 8:10 AM