From a migration. I want to initialize a new column called "ident" with
a string equal to "prec-#{id}" - where id is meant to be the id column
of the relevant row. This works:
Precinct.update_all("ident = 'prec-' || id ")
I am confused about whether that bit of SQL is being parsed by Rails
code, or whether it's given to Sqlite, in which case I am writing a
database-dependent bit of code.
From a migration. I want to initialize a new column called "ident" with
a string equal to "prec-#{id}" - where id is meant to be the id column
of the relevant row. This works:
Precinct.update_all("ident = 'prec-' || id ")
I am confused about whether that bit of SQL is being parsed by Rails
code, or whether it's given to Sqlite, in which case I am writing a
database-dependent bit of code.
I believe it's going to the database, but I haven't verified it.
Follow the source though to make sure...
first line of update_all is:
sql = "UPDATE #{quoted_table_name} SET #{sanitize_sql_for_assignment(updates)} "
So, worth looking at sanatize_sql_for_assignment to see what it might be doing.
From a migration. I want to initialize a new column called "ident"
with
a string equal to "prec-#{id}" - where id is meant to be the id column
of the relevant row. This works:
Precinct.update_all("ident = 'prec-' || id ")
I am confused about whether that bit of SQL is being parsed by Rails
code, or whether it's given to Sqlite, in which case I am writing a
database-dependent bit of code.
I believe it's going to the database, but I haven't verified it.
It would have to be going to the DB, or else || wouldn't have its SQL
sense of concatenation.
To the OP: if this column is just going to be the id with a constant
prefix, then you don't need it in the DB!
Follow the source though to make sure...
first line of update_all is:
sql = "UPDATE #{quoted_table_name} SET
#{sanitize_sql_for_assignment(updates)} "
So, worth looking at sanatize_sql_for_assignment to see what it might
be doing.