1

Using python to scrape IMDB for some famous movie quotes and insert it into a postgresql database. After scrape data looks as such

[['The Godfather', "A man who doesn't spend time with his family can never be a real man", 'Car Wash', '25th Hour', 'Tootsie'], 
['The Usual Suspects', "The greatest trick the devil ever pulled was convincing the world he didn't exist ... and like that, he's gone", 'The Hustler', 'The Good, the Bad and the Ugly', 'Les aventures de Rabbi Jacob'].... ]

Table scheme

"Wrong2" character varying COLLATE pg_catalog."default" NOT NULL,
"Wrong1" character varying COLLATE pg_catalog."default" NOT NULL,
"Question" character varying COLLATE pg_catalog."default" NOT NULL,
"Id" integer NOT NULL,
"Answer" character varying COLLATE pg_catalog."default" NOT NULL,
"Wrong3" character varying COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT question_pkey PRIMARY KEY ("Id")

Query

id = None
stmt = "INSERT INTO public.question (Answer, Question, Wrong1, Wrong2, Wrong3) VALUES(%s, %s, %s, %s, %s);"
data = (databaseValueList[0][0], databaseValueList[0][1], databaseValueList[0][2], databaseValueList[0][3], databaseValueList[0][4])
cur.execute(stmt, data)
id = cur.fetchone()[0]
print(id)
conn.commit()
cur.close()

Reply

column "answer" of relation "question" does not exist
LINE 1: INSERT INTO public.question (Answer, Question, Wrong1, Wrong...

I've tried making it all lower case on off chance it mattered (I've read since I didn't use quotes it shouldn't), casting to string str(databaseValueList[0][1]) and a couple other things to no avail. Any ideas on what direction to figuring it out would be appreciated.

0

1 Answer 1

1

The columns in your table have quoted identifiers as names. Use the quotes in the query:

stmt = 'INSERT INTO public.question ("Answer", "Question", "Wrong1", "Wrong2", "Wrong3") VALUES(%s, %s, %s, %s, %s);'
Sign up to request clarification or add additional context in comments.

1 Comment

That seems to of done it, could of swore I had tried that as I read a couple posts about that same problem. Thank you kindly!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.