Skip to content
Advertisement

Columns with keywords as names in PostgreSQL

I have a couple of tables which have keywords as column names. I am not able to write a subquery using them. Even if I use non-existing column names, the query works. For example

I have a few questions – when I use a non-existing column name in a subquery, it works. But if I use the same column name in a query, I get an error. How can I use key-word column names in a subquery without running into surprises like this? I know that using keywords as column names is not a good idea, but the system has been around for 2 decades and changing column names is not an option now.

Advertisement

Answer

when I use a non-existing column name in a subquery, it works.

Well, but not the way you think it works.

It will resolve to the column in some other part of the query (here the other table).

is the same as

This is not related to “view” being a bad choice for a column name, the same thing happens if your column is called “x”.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement