Postgresql – Select statement to table with percentage column names

postgresql

I am selecting data from one table that have percentage sign in some column names like:

| name | val% | vale2% | 

This table is ofted use with select * from table, but in this case I need only the field names with percentage sing, when I run a select in query tool of pgadmin this notice this error:

ERROR:  syntax error at or near "as"
LINE 1: SELECT val% as value, val2% as value2 from table

How I can run this query and get only val% and val% without the rest of fields.

NOTE: I can change the database structure, only query it data

Best Answer

Moved from comment to answer, as it seemed to resolve the OP's problem:

It sounds like the actual column names are causing your problem. If so, then you need to quote them somehow. Depending on the settings for your database:

SELECT "val%" as value, "val2%" as value2 from table

may work. In some SQL variants, you can use square brackets [] to quote column names that conflict with language keywords and operators:

SELECT [val%] as value, [val2%] as value2 from table