Odoo Help


problem with sql query writting

on 7/3/13, 5:29 AM 1,737 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
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
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

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)


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