On 03/07/2014 08:25 PM, Jeremy Evans wrote:
On Friday, March 7, 2014 3:43:24 PM UTC-8, Joel VanderWerf wrote:


    I'm using sqlite and apparently it wasn't compiled with the
    SQLITE_ENABLE_UPDATE_DELETE_LIMIT, so I can't do something like

    delete from table where ... order by ... limit 1;

    This works: subquery for the unique id and then delete that:

    table = DB['tablename']


I think you mean DB[:tablename] :)

    table.where(id: table.select(:id).where(...).limit(1)).delete

    Is there any sequel trick to delete at most one row that I'm missing?


On the databases that support it (currently only MySQL):

DB[:table].order(:a).limit(1).delete
# DELETE FROM table ORDER BY a LIMIT 1"

For anything remotely portable, your subquery approach is probably best.

Thanks! Not likely to use MySQL, so will stick with subquery. Good to know that's the best approach.

(I make the DB['tablename'] mistake too often...)

--
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to