Ali
Ali

Reputation: 7483

SQL error on PostgreSQL database on Heroku - can't run update

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

Upvotes: 0

Views: 354

Answers (1)

John Woo
John Woo

Reputation: 263723

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', '');

Upvotes: 3

Related Questions