1

When I write a PostgresSQL engine query in Python using the sqlalchemy toolkit, I get errors such as 'column name does not exist'.

For example:

df = pd.read_sql_query('SELECT Descriptor FROM data LIMIT 3', engine)

But with the following modification there is no error:

df = pd.read_sql_query('SELECT \"Descriptor\" FROM data LIMIT 3', engine)

Is there any way I can avoid having to do this additional step (i.e., adding slashes) by perhaps using some type of global setting?

6
  • Rename you tables to lower case if you can. Commented Dec 17, 2016 at 6:38
  • if you are using sqlalchemy why are you writing raw queries like this? Commented Dec 17, 2016 at 6:52
  • @e4c5 my friend, I am following this tutorial since I am a new learner to sql and sqlalchemy. Can you suggest an example of an alternative way to write the query I have in my initial post. thank you. Commented Dec 17, 2016 at 6:56
  • @teppic thank you for the suggestion. I have thought of this, is there any other alternative? Is postgres sensitive to uppercase/lowercase? Commented Dec 17, 2016 at 6:58
  • @R.A.P: You already have an answer to address that. The tutorial you link to is not even targeted at Postgres to begin with. Commented Dec 17, 2016 at 6:59

1 Answer 1

1

Use legal, lower-case identifiers. Then you don't need double-quotes to preserve mixed-case spelling for identifiers.

The tutorial you link to is targeted at SQLite, not Postgres. But all the identifiers would work in Postgres all the same if you did not create tables and columns with double-quotes to preserve mixed-case spelling, since unquoted identifiers are lower-cased automatically in Postgres.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.