Skip to content

Instantly share code, notes, and snippets.

@dinedal
Created June 19, 2013 22:23
Show Gist options
  • Save dinedal/5818668 to your computer and use it in GitHub Desktop.
Save dinedal/5818668 to your computer and use it in GitHub Desktop.
# Case 1: raw values
DB[:foo].insert_sql(a:1)
# => "INSERT INTO \"foo\" (\"a\") VALUES (1)"
# Case 2: from another dataset
DB[:foo].insert_sql(DB[:foo].where(b:1))
# => "INSERT INTO \"foo\" SELECT * FROM \"foo\" WHERE (\"b\" = 1)"
# Case 3: raw values with conditionals
DB[:foo].where(b:1).insert_sql(a:1)
# => "INSERT INTO \"foo\" (\"a\") VALUES (1)"
# My question is, why doesn't this return:
# => "INSERT INTO \"foo\" (\"a\") SELECT 1 FROM \"foo\" WHERE (\"b\" = 1)"
# And, is there a way to ask Sequel to build said statement w/o dropping to raw SQL?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment