Can we create two (or more) columns in Postgres/ MySQL with the same name but a different case? As in does case-sensitivity matter in column names?
For e.g., Can a table contain two columns with names – COL
and col
?
Linked post: can we create two columns with same name in database? only talks about same names, but not about case sensitivity.
2
Answers
In standard SQL, quoted identifiers are case sensitive and Postgres follows that standard.
So the following:
Or as part of a table
Those are two different names as they become case sensitive due to the use of the double quotes.
But I would strongly advise to not do that. This will most probably create confusion and problems down the line.
I think this should work with MySQL as well, but as it traditionally doesn’t care about following the SQL standard, I don’t know.
Not possible to create columns with same name – yes case-sensitivity matters.
Example in MySQL:
Output in MySQL:
Output in PostgreSQL:
SELECT statement:
Output:
Case-sensitive SELECT:
Output: