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:[email protected]: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?

2
  • 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. Commented Dec 12, 2018 at 7: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. Commented Dec 12, 2018 at 9:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@ 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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.