Getting Stomped On

|  Categories:  Tech   Self-Development  

For the past two weeks I've had a homework assignment due that I haven't been able to complete. I can program a website enough to make this one, but with all due respect to actual programmers, this wasn't that hard to make. There are YouTube videos that can walk you through building one yourself. Taking this class was born from the desire to learn more and have a way to sharpen my development skills. The class has been great but one homework/project has been getting the best of me and out of me. It took a week to figure out a Postgres query that would pull data from a CSV and place it in it's appropriate tables. Exact solutions were nowhere to be found online. My problem seemed somewhat unique or maybe I didn't word my searches in a way that produced the answer. But I am glad I wasn't able to. Not finding the solution readily available forced me to go through the documentation and learn how to solve the problem myself. Currently reading "The War of Art" by Steven Pressfield and thought this excerpt was cool. “It’s better to be in the arena, getting stomped by the bull, than to be up in the stands or out in the parking lot.” The problem I was trying to solve was: - From a csv containing book information (isbn, title, year published, author), split up into two tables: 1. Author 2. Books I wanted an Author table so not to repeat myself when an Author had multiple books. This is known as DRY (Don't Repeat Yourself). Importing the books that referenced the Author was where the challenge took place and I was getting torn asunder. Now I could have just manually imported but the assignment asked to only use the SQLAlchemy execute function. This was my result: self.cur.execute("WITH author AS (SELECT id, name FROM authors WHERE name = %s) INSERT INTO books(isbn, title, year, author_id) VALUES(%s, %s, %s, (SELECT author.id FROM author))", (str(row[2]), str(row[0]), str(row[1]), int(row[3])))

Add comment
Comments: