Was following a tutorial on medium about postgres. Here's the article - link
At some point he tries to create a table and insert test values. Later he tries to print the table using some code which I have pasted below -
import psycopg2
hostname = 'localhost'
username = 'postgres' # the username when you create the database
password = '***' #change to your password
database = 'quotes'
def queryQuotes( conn ) :
cur = conn.cursor()
cur.execute( """select * from quotes_content""" )
rows = cur.fetchall()
for row in rows :
print (row[1])
conn = psycopg2.connect( host=hostname, user=username, password=password, dbname=database )
queryQuotes( conn )
conn.close()
I followed the same and created a table named jobs
(mind the case).
create table jobs(id serial primary key, job-link text, company text, job-title text)
insert into jobs(job-link, company, job-title) values('test-link','test-company','test-job')
When I created my queryJobs
function in the execute()
line, I tried the following select
statements but all of them return a SyntaxError
-
"""select * from jobs""" returns psycopg2.errors.UndefinedTable: relation "jobs" does not exist
"""select * from "jobs"""" returns SyntaxError: EOL while scanning string literal
"select * from "jobs"" returns SyntaxError: invalid syntax
"""select * from 'jobs'""". returns psycopg2.errors.SyntaxError: syntax error at or near "'jobs'"
I tried using multiple versions of quotes because I read in this answer that there is some case sensitivity issue in Postgres tables. Refer the answer given by @Mitzi in this question.