0

I am new to PostgreSQL and trying the below two scenarios:

  1. Select a column name which already has a forward slash(/) in database (Road/Highway)
  2. Using case on same column along with index
Select Road/Highway, 
case 
 when index(upcase(Road/Highway), 'xturn') > 0 then 2
 else 0
end as preferred_road
from abc_data;

But I am getting syntax error near index and for slash it is only taking Road.

1

1 Answer 1

2

Generally / means "division", so your column name is non-standard, much like working with keyword column names, column names with special characters must be quoted with double quotes. Use "Road/Highway" when referring to the column.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the correcction!
Thanks @Gregor , any thoughts on the case part?
Use double quotes everywhere you refer to the column. Without quotes, it will look for a column name "Road" and a column named "Highway" and try to divide them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.