Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Last active January 10, 2021 15:59
Show Gist options
  • Select an option

  • Save narenaryan/f0baa38ef1631f39390f750f7c327f61 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/f0baa38ef1631f39390f750f7c327f61 to your computer and use it in GitHub Desktop.
cursor-illu
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