Results 1 to 4 of 4
Oct 17, 2007, 05:29 #1
How to use a custom INSERT sql query?
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?
Oct 17, 2007, 05:46 #2
- Join Date
- Jan 2006
- 0 Post(s)
- 0 Thread(s)
You should be able to use
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.
Oct 17, 2007, 07:23 #3
anyway i'm using the rails transaction...will they work the same with this custom sql?
Oct 17, 2007, 11:35 #4
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.