3

I am trying to run a basic select Query in PostgreSQL, but I am having trouble using the column alias. I tried to create the alias as randomfield As [Space In Name] but it gave an error of

Error: syntax error at or near "["
Line 2: randomfield As [Space In Name]

And I also tried to do the alias w/o the brackets but that presented an error as well. How do you alias with a space in Postgresql?

Select randomfield As [Space In Name]
From saledata
Neil McGuigan
  • 7,653
  • 3
  • 36
  • 52

1 Answers1

5

Identifiers with special characters require double quotes in SQL:

SELECT randomfield AS "Space in Name" FROM saledata
a_horse_with_no_name
  • 69,148
  • 13
  • 135
  • 173
Jonathan Fite
  • 7,306
  • 1
  • 17
  • 26