patternsqlMajor
Quoting columns with spaces in PostgreSQL?
Viewed 0 times
postgresqlquotingcolumnswithspaces
Problem
I migrated a database from SQL Server to PostgreSQL.
Most column names contain double words, for example:
...which does not work in PostgreSQL.
What is the correct syntax for PostgreSQL?
Most column names contain double words, for example:
SELECT [Column Name] FROM table;...which does not work in PostgreSQL.
What is the correct syntax for PostgreSQL?
Solution
In most RDBMSs, double-quotes are what are used to specify an exact spelling of something.. (single quotes being string delimiters).
Notice that capital/lowercase also matters when using double-quotes. (Postgres lower-cases everything when double-quotes are not used ... Oracle upper-cases everthing, etc..)
in postgres, is different from
where as in oracle, is different from
SELECT
tab."This IS My Column EXACTLY" AS col
FROM "My TabLE Name Contains Spaces Too!" tab
WHERE tab."ANOTHER UGLY COLUMN name" = 'MyFilterString';Notice that capital/lowercase also matters when using double-quotes. (Postgres lower-cases everything when double-quotes are not used ... Oracle upper-cases everthing, etc..)
SELECT COLUMN1 FROM TABLEin postgres, is different from
SELECT "COLUMN1" FROM TABLEwhere as in oracle, is different from
SELECT "column1" FROM TABLECode Snippets
SELECT
tab."This IS My Column EXACTLY" AS col
FROM "My TabLE Name Contains Spaces Too!" tab
WHERE tab."ANOTHER UGLY COLUMN name" = 'MyFilterString';SELECT COLUMN1 FROM TABLESELECT "COLUMN1" FROM TABLESELECT "column1" FROM TABLEContext
StackExchange Database Administrators Q#118059, answer score: 30
Revisions (0)
No revisions yet.