简体   繁体   中英

Workaround for DELETE … LIMIT clause (SQL)

I am working on a database query abstraction layer that supports SQLite.

Unfortunately, SQLite does not support the LIMIT clause in DELETE (and UPDATE etc.) queries - except if compiled with a special flag in more recent versions.

So is there any workaround that I could implement so that that query type can still be supported?

Although LIMIT is not innately supported in your build of SQLite you may be able to reproduce the behavior by implementing a method that uses a LIMIT select in a subquery to identify the rows that will be updated or deleted. You should be aware that this will cause some performance degradation over using a LIMIT enabled SQLite build but if you need the functionality this would seem like a viable option.

If you are working with a large set of data or find that the performance hit from trying this is too severe the other option would be to use a LIMIT select to populate a temp table and then join against that table as part of your delete or update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM