1

I would like the following SQL query to be executed in a migration file after adding a column (updating the new field with existing column value from the same row)

UPDATE users SET last_login=updated_at;

The SQL statements work properly when executed on the database, but in rails I tried multiple syntax using the ActiveRecord update_all method but without success

User.update_all("last_login=updated_at")

I get the following error

ActiveRecord::StatementInvalid: PGError: ERROR:  current transaction is aborted, commands ignored until end of transaction block
: UPDATE "users" SET last_login=updated_at

Obviously something is missing in my syntax, but can't figure out what. Can anyone point me to the right syntax?

Regards/J.

jlamberc
  • 85
  • 8

1 Answers1

3

Syntax is indeed correct, the issue was relying in the fact that I had to rollback the previous transaction.

User.update_all("last_login=updated_at")

This statement works properly.

Community
  • 1
  • 1
jlamberc
  • 85
  • 8