Sign in
Log inSign up

Executing SQL query with Python

anuj tyagi's photo
anuj tyagi
·Sep 20, 2016

I need to run below Sql query through a python code and get the output of it. How can I make it work using "os" module. I can't install sql module on the system where I have to execute this query in python.

Program should run this sql query, check for the account id in database and execute the output from sql query. I havent worked with sql from long time, getting issue to understand it.

It should be something like this but something is wrong here:

import os 

id = raw_input("Enter account_id:")

os.system('sql2 -q abc.dev.domain.com "select account_name, account_id, is_enrolled from (select * from my_db where account_id = '$id' and is_enrolled = check by account_name')