i'm getting the below error while executing the below statement(excluded the connection and cursor part).Does anyone have any idea on this?

Error while fetching data from PostgreSQL 'builtin_function_or_method' object has no attribute 'execute'

-- Sub function---

def psql_command(msql, psql, msql_command, psql_command):

    msql.execute(msql_command)

    for row in cur_msql:
        try:
            psql.execute(command, row)
        except psycopg2.Error as e:
            print ("Cannot execute the query!!", e.pgerror)

            sys.exit("Some problem occured with the query!!!")

---Main Function ------

# Read all connection information from config.ini
    #config = get_config_object()
 try:
   cnx_msql = psycopg2.connect(user="sandy",
                                  password="postgres",
                                  host="127.0.0.1",
                                  port="5432",
                                  database="postgres")
 except mysql.connector.Error as e:
   print ("MYSQL: Unable to connect!", e.msg)
   sys.exit(1)


# Postgresql connection
 try:

   cnx_psql = psycopg2.connect(user="Postgres",
                                  password="postgres",
                                  host="127.0.0.1",
                                  port="5432",
                                  database="Clone")
  #cnx_psql = psycopg2.connect(conn_string_psql)
 except psycopg2.Error as e:
   print('PSQL: Unable to connect!\n{0}').format(e)
   sys.exit(1)

# Cursors initializations
 cur_msql = cnx_msql.cursor

 cur_psql = cnx_psql.cursor()



commands = [("SELECT 
 customer_id,entity_id,store_id,created_at,updated_at,items_count,base_row_total,row_total,base_discount_amount,base_subtotal_with_discount,base_to_global_rate,is_active from sales_flat_quote where is_active=1 AND items_count != '0' AND updated_at > '2019-05-09 00:00:00';",
             "INSERT INTO staging.sales_flat_quote (customer_id,entity_id,store_id,created_at,updated_at,items_count,base_row_total,row_total,base_discount_amount,base_subtotal_with_discount,base_to_global_rate,is_active) \
              VALUES (%(customer_id)s, %(entity_id)s, %(store_id)s, %(created_at)s, %(updated_at)s, %(items_count)s, %(base_row_total)s, %(row_total)s, %(base_discount_amount)s, %(base_subtotal_with_discount)s, %(base_to_global_rate)s, %(is_active)s)"),

            ("SELECT store_id,row_total,updated_at,qty,sku,free_shipping,quote_id,price,no_discount,item_id,product_type,base_tax_amount,product_id,name,created_at from sales_flat_quote_item WHERE updated_at > '2019-05-09 00:00:00'",
             "INSERT INTO staging.sales_flat_quote_item (store_id,row_total,updated_at,qty,sku,free_shipping,quote_id,price,no_discount,item_id,product_type,base_tax_amount,product_id,name,created_at) VALUES (%(store_id)s, %(row_total)s, %(updated_at)s, %(qty)s, %(sku)s, %(free_shipping)s, %(quote_id)s, %(price)s, %(no_discount)s, %(item_id)s, %(product_type)s, %(base_tax_amount)s, %(product_id)s, %(name)s, %(created_at)s)"),

            ("SELECT select created_at,url_path,price,short_description,url_key,thumbnail_label,small_image,thumbnail,name,sku,type_id from catalog_product_flat_1", 
             "INSERT INTO staging.catalog_product_flat_1 (created_at,url_path,price,short_description,url_key,thumbnail_label,small_image,thumbnail,name,sku,type_id) \
              VALUES (%(created_at)s, %(url_path)s, %(price)s, %(short_description)s, %(url_key)s, %(thumbnail_label)s, %(small_image)s, %(thumbnail)s, %(name)s, %(sku)s, %(type_id)s)")

            ]

   for msql_command, psql_command in commands:
       print(msql_command)
       print(psql_command)

       psql_command(cur_msql, cur_psql, msql_command, psql_command)

1 Answers

0
Z.Amir On Best Solutions

cur_msql = cnx_msql.cursor this should be cur_msql = cnx_msql.cursor() as this is a method