Skip to content

Instantly share code, notes, and snippets.

@pmartinez8241
Last active May 20, 2023 00:02
Show Gist options
  • Save pmartinez8241/d00d95e35abac0b83aaefbb1135ff9f4 to your computer and use it in GitHub Desktop.
Save pmartinez8241/d00d95e35abac0b83aaefbb1135ff9f4 to your computer and use it in GitHub Desktop.
How to create, then use, a postgres REFCURSOR in postgres
import psycopg2
import json
def get_drives_and_media_type():
results = []
with psycopg2.connect("host=# dbname=entertainment_database user=# password=#") as conn:
with conn.cursor() as db_cursor:
db_cursor.callproc('GET_DRIVES_AND_MEDIA_TYPES',['something'])
with conn.cursor('something') as cursor2:
for x in cursor2:
results.append({'table_name':x[0],'id':x[1],'name':x[2],'storage_type':x[3]})
return results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment