|Related to : Ruby on Rails - reverse add_column, add_index migration|
|Editing rails migration table doesn't affect tables generated|
This is exactly what you want. It creates the same column, while
adding an index as well. add_reference creates the column with the
name you specified, which in your case is the same as the original
migration. If you run SHOW INDEXES on the table, you should see the
newly created index as well.
|R: fill a new column in a data frame with a value by matching variables in reverse|
Try merge. The by.x and by.y arguments specify columns to be matched,
and here the order of matching columns is reversed in by.y:
merge(x = df, y = df, by.x = c("x", "y"), by.y = c("y", "x"))
# x y value_xy.x value_xy.y
# 1 A B 7 3
# 2 A C 2 2
# 3 B A 3 7
# 4 B C 6 1
# 5 C A 2 2
# 6 C B 1
|Update table by column index not by column name|
As per the comments you can do it with dynamic SQL (not recommended)
due to security implications or the below.
ID = IF(colparameter=1, valueparam, ID),
name = IF(colparameter=2, valueparam, name),
price = IF(colparameter=3, valueparam, price)
where ID = 5
Even this I wouldn't recommend doing.
|Rails index uniqueness with specific value|
I don't believe you can have conditional uniqueness constraints at the
database layer (via migrations). You can add this as a conditional
validation at the AR layer though which should be sufficient for your
purposes (though it should be noted this can introduce some race
validates [:col1, :col2], uniqueness: true, if: ":col3 == true"
Hope that helps.
|Convert a column to an index in pandas|
You can simply use the set_index method for this:
This take the column out of the DataFrame and sets it as the
DataFrame's index. The method also allows you to quickly set multiple
columns as indexes or check whether the new index contains duplicates.