Home > Enterprise >  Postgres doesn't let me use '$' in column alias
Postgres doesn't let me use '$' in column alias

Time:09-28

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?

CodePudding user response:

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.

  • Related