Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been having issues in storing variables(parameter replacement) into the database in postgresql using flask; below is what i did but it was not executed; what could be the issue
username: 'Pat'
email: 'pat@gmail'
password: 'pat'

values = {"username": username, "email": email, "password": password}
engine.execute("INSERT INTO users (username, email, password) VALUES (:username,    :email, :password)", values)


What I have tried:

username: 'Pat'
   email: 'pat@gmail'
   password: 'pat'

   values = {"username": username, "email": email, "password": password}
   engine.execute("INSERT INTO users (username, email, password) VALUES (:username,    :email, :password)", values)
Posted
Updated 16-Apr-20 6:42am
Comments
Richard Deeming 16-Apr-20 11:45am    

1 solution

Maybe you need to make a connection first, see example here: How to Execute Raw SQL in SQLAlchemy | Tutorial by Chartio[^]

It could also be that your changes are executed but not committed, so you might need to use something like this:
result = db.engine.execute(text("<sql here>").execution_options(autocommit=True))
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900