I see that there is no way to do a custom INSERT sql query in rails. I need it 'cause i have to use the IGNORE clause with INSERT on a primary key index on a database table. How can i do that?
| SitePoint Sponsor |
I see that there is no way to do a custom INSERT sql query in rails. I need it 'cause i have to use the IGNORE clause with INSERT on a primary key index on a database table. How can i do that?


You should be able to use
Code ruby:YourModel.find_by_sql("INSERT IGNORE...") # or YourModel.connection.execute("INSERT IGNORE...")
If you give someone a program,
you will frustrate them for a day;
if you teach them how to program,
you will frustrate them for a lifetime.
anyway i'm using the rails transaction...will they work the same with this custom sql?
another question....is this using of INSERT IGNORE... worth in term of performance? Currentely i'm lopping through the textfile lines and first i make a find on the database with the field values taken form the current file line then, if i found already that file line inserted in the database i will not insert it otherwise i create a new row in the database.
Bookmarks