0

I need to run an update query over a database I have set up on a rails site on heroku. Its a simple query however for some reason when I try to run the sql from the sql console i.e Heroku sql I get a syntax error. I don't know whats wrong with the sql it seems fine to me:

SQL> UPDATE service_types SET desc = replace(desc, ' Charge', '');
PGError: ERROR:  syntax error at or near "desc"
LINE 1: UPDATE service_types SET desc = replace(desc, ' Charge', '')...

Any ideas

1 Answer 1

3

escape it using double quotes (the easiest way, i know there's another)

UPDATE service_types SET "desc" = replace("desc", ' Charge', '');

or assign an ALIAS

UPDATE service_types a SET a.desc = replace(a.desc, ' Charge', '');

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

4 Comments

@JW. Renaming the column (to e.g. descr) is probably better in the long run though.
@a_horse_with_no_name I definitely agrees with you. I was just assuming that he cannot alter the tables. Anyway great comment. using reserved keyword will give pain in the neck in the future. :D
ouch so desc is a reserved keyword here - I didnt know that - thanks for the tip! Time for some major database refactoring
@Ali: It's the indicator whether you want to sort ascending or descending: select .. order by some_col desc.

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.