Last active
January 10, 2021 15:59
-
-
Save narenaryan/f0baa38ef1631f39390f750f7c327f61 to your computer and use it in GitHub Desktop.
cursor-illu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from psycopg2 import connect | |
| import time | |
| # Get this from ENV variables or configuration store | |
| config = { | |
| "host": "db", | |
| "dbname": "dvdrental", | |
| "user": "postgres", | |
| "password": "mypassword", | |
| "port": "5432" | |
| } | |
| def main(): | |
| sql_query = 'SELECT * FROM actor WHERE first_name LIKE %s' | |
| with connect(**config) as conn: | |
| with conn.cursor() as cur: | |
| cur.execute(sql_query, ["John%"]) | |
| res = cur.fetchall() | |
| print("Fetched records: %s" % res) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment