SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyway i'm using the rails transaction...will they work the same with this custom sql?

  4. #4
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •