0

I am taking a course in DataCamp on databases and there is a part where I access the census database in AWS using SQLalchemy.

The code is:

engine = \
create_engine('postgresql+psycopg2://student:datacamp@postgresql.csrrinzqubik.us-east-1.rds.amazonaws.com:5432/census')

When I run this code and then try to access the data from my Jupyter Notebook I get a message that tells me that access is denied.

metadata = MetaData()

census = Table('census', metadata, autoload = True, autoload_with = engine)

connection = engine.connect()

stmt = select([census])

stmt = stmt.where(census.columns.state == 'New York')

results = connection.execute(stmt).fetchall()

ProgrammingError: (psycopg2.ProgrammingError) permission denied for relation census
 [SQL: 'SELECT census.state, census.sex, census.age, census.pop2000, census.pop2008 \nFROM census \nWHERE census.state = %(state_1)s'] [parameters: {'state_1': 'New York'}]

I have an account in AWS. What should I do to access the census database from my Jupyter Notebook?

halfer
  • 19,824
  • 17
  • 99
  • 186
user8270077
  • 4,621
  • 17
  • 75
  • 140
  • Doesn't the course DataCamp have a forum or Q&A where students can ask questions regarding the lectures? Perhaps someone there had the same problem and it has already been solved. – Edgar Ramírez Mondragón Dec 12 '18 at 07:42
  • @ Edgar: Thanks for the suggestion. They have a chat area in Slack and I have posted the question there as well. However, this is a more general question and can be answered by the Stackoverflow community as well and perhaps better and faster. – user8270077 Dec 12 '18 at 09:40

1 Answers1

0

Well...it seems to be an issue with user permissions.

I have no problem either reading the column names (census.state, census.sex, census.age, census.pop2000, census.pop2008), or running queries on other tables:

>>> res = connection.execute('SELECT * FROM data')
>>> res.fetchall()
[(10, 'boobs'), (11, 'ass'), (11, 'ass'), (12, 'usa'), (12, 'usa'), (12, 'usa'), (12, 'usa'), (12, 'usa'), (12, 'usa'), (12, 'usa'), (12, 'usa'), (12, 'usa'), (12, 'usa')]

The permission denied for relation tablename error might be due to insufficient privileges granted for the user on the census table. You might want to contact the DataCamp instructor or other students there.

  • @ Edgar: Thanks Edgar for your time. As I have said I have already taken steps to contact DataCamp. Still, since I have an AWS account and census is a public dataset open to to everyone interested, could you guide me on the steps to get access to it? – user8270077 Dec 12 '18 at 20:34