0

Postgres 14.
Are there any forbidden characters in aliasing columns?
I want to see '$' in column's name and it doesn't work. How can I get it done? Is there any magic function that could do that for me?

SELECT 
    id,
    currency as '$',
    available
from f_total
ORDER BY 
    id DESC
;

gives:

ERROR:  syntax error at or near "'$'"
LINE 3:  currency as '$',
                     ^
SQL state: 42601
Character: 27

Same story when I use '€', '!', '<'. I expected it to be not executed against all syntax-verificators - it's just an insignificant string to be used on output ... How to make my column to be named with such name?

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • 4
    Identifiers like column aliases are delimited with double quotes (`"`) not apostrophes (`'`) – Bergi Sep 28 '22 at 02:13

1 Answers1

2

Use double-quotes (") for identifiers:

currency AS "$"

See:

Every string is allowed once double-quoted (with contained double-quotes doubled up). Doesn't mean it's a good idea to use "$" as identifier. It isn't.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228