Hello Everyone!
Would you kindly help figure out how to manage to carry out the following task. I have a database with two table, jobs (where there some data I'm interested in) and picks (where I'm looking to copy/insert data coming from jobs.
I'm working in Flask and Postgres, with my current code (below) I get error message: "Invalid syntax". Thank you for your help.
Would you kindly help figure out how to manage to carry out the following task. I have a database with two table, jobs (where there some data I'm interested in) and picks (where I'm looking to copy/insert data coming from jobs.
I'm working in Flask and Postgres, with my current code (below) I get error message: "Invalid syntax". Thank you for your help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
@app .route( '/apply/<job_id>/' , methods = [ 'GET' , 'POST' ]) @login_required def apply (job_id): for_listing = Job.query.get(job_id) applicant = session[ 'username' ] date_applied = datetime.now() try : connection = psycopg2.connect(user = "postgres" , password = "mypassword" , host = "127.0.0.1" , port = "5432" , database = "jobapplied" ) cursor = connection.cursor() postgres_insert_query = INSERT INTO picks (for_listing, applicant, date_applied, jobname, jobdesc ) (SELECT job_name, job_desc, FROM jobs WHERE id = for_listing) cursor.execute(postgres_insert_query) connection.commit() flash ( "Record inserted successfully into the picks table" ) except (Exception, psycopg2.Error) as error : if (connection): flash ( "Failed to insert record into picks table" , error) finally : #closing database connection. if (connection): cursor.close() connection.close() |