Created
July 31, 2020 17:20
-
-
Save CodeDrome/73c24ca60ee399dd6906a2f3f1cd9ead to your computer and use it in GitHub Desktop.
pgdml.py Part 5
This file contains 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
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