how to manually change record in heroku database
Asked Answered
K

2

7

I have a rails app hosted in heroku. I have a Questions table with a content column. The content column contains the word of a question. So for example if you queried. Question.first.content, you would get "Hello, how are you?". I have 8 questions in total. I would like to manually go into the database and change these questions.

I tried running the terminal on heroku with this command:

heroku pg:psql

and I used this query to change the content column of a record

UPDATE Questions
SET content="What country does this story orginate? (Japan)"  

However I get this error message:

ERROR: column "What country does this story orginate? (Japan)" does not exist
LINE 2: SET content="What country does this story orginate? (Japan)"...

What is the right query of changing the question's content column?

Kippie answered 16/5, 2015 at 18:22 Comment(2)
postgresql.org/docs/current/static/…Fulmination
Or you can you rails console - heroku run rails cTwotone
K
5

It turns out I can do heroku run console. Once in the console I can do active record queries such as Question.find(1).update_attributes(:content=>'how are you?') and it updates. For whatever reason heroku run rails console did not update the record with active record queries but just returned that the query was successful.

Kippie answered 19/5, 2015 at 15:15 Comment(0)
C
2

SQL uses single quotes for string literals and double quotes for identifiers (such as table and column names), that's why you're getting a complaint about an unknown column. The fix is simple, use single quotes for the string literal:

update questions set content = '...' where ...

Some databases let you use double quotes for strings but that's non-standard and should be avoided.

Conformance answered 16/5, 2015 at 18:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.