Skip to content

Instantly share code, notes, and snippets.

@CodeDrome
Created July 31, 2020 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeDrome/73c24ca60ee399dd6906a2f3f1cd9ead to your computer and use it in GitHub Desktop.
Save CodeDrome/73c24ca60ee399dd6906a2f3f1cd9ead to your computer and use it in GitHub Desktop.
pgdml.py Part 5
def select_photos():
# Wildcards:
# percent sign % for 0 or more characters
# underscore _ for exactly 1 character
select_dict = {"where_like": '%Oslo%'}
try:
conn = pgconnection.get_connection("codeinpython")
cursor = conn.cursor()
# To make LIKE case insensitive use ILIKE
cursor.execute("SELECT galleryid, title, description, photographer, datetaken FROM photos WHERE description LIKE %(where_like)s;", select_dict)
# get a list of tuples containing the data
data = cursor.fetchall()
cursor.close()
conn.close()
for row in data:
print(row)
except psycopg2.Error as e:
print(type(e))
print(e)
def select_galleriesphotos():
try:
conn = pgconnection.get_connection("codeinpython")
cursor = conn.cursor()
cursor.execute("SELECT galleryname, gallerydescription, phototitle, photodescription FROM galleriesphotos")
# get a list of tuples containing the data
data = cursor.fetchall()
cursor.close()
conn.close()
for row in data:
print(row)
except psycopg2.Error as e:
print(type(e))
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment