A prettier query

Screen Link:
https://app.dataquest.io/m/246/creating-tables/11/date-type

I believe to have foud a slight aesthetic improvement upon this answer.

My Code:

import psycopg2
conn = psycopg2.connect("dbname=dq user=dq")
cur = conn.cursor()
cur.execute("""
ALTER TABLE ign_reviews
ADD COLUMN release_date date
""")
cur.execute("""
ALTER TABLE ign_reviews
DROP COLUMN release_year,
DROP COLUMN release_month,
DROP COLUMN release_day;
            """)
conn.commit()
conn.close()

The answer code:

import psycopg2
conn = psycopg2.connect("dbname=dq user=dq")
cur = conn.cursor()
cur.execute("ALTER TABLE ign_reviews ADD COLUMN release_date date;")
cur.execute("ALTER TABLE ign_reviews DROP COLUMN release_year;")
cur.execute("ALTER TABLE ign_reviews DROP COLUMN release_month;")
cur.execute("ALTER TABLE ign_reviews DROP COLUMN release_day;")
conn.commit()
conn.close()

I know it might be a little precise especially when just learning this, but I believe that one single query is prettier than the DQ solution. On the other hand. The result is just the same and I am just sharing this for completeness purposes :v:

1 Like

@DavidMiedema: I recategorized your post.