SQLite Forum

Can an application-defined function be used to convert one row of data to multiple rows and insert them into another table?
Login
> If the procedure is changed to write each row from within it, as below, it works. But is this the correct approach?

That approach offends a value known as "<u>[Separation of Concerns](https://en.wikipedia.org/wiki/Separation_of_concerns)"</u>. You would need to rename the function to SplitToWordsAndStuffIntoSomeDB(), and it would still be doing disparate things.

A cleaner approach would be to get the word list, then iterate over it using TCL with each loop doing an insert. This might induce worry about efficiency, but the SQLite/TCL library caches some statements to avoid recompilation in loops such as you would write.

BTW, I empathize with your sentiment that it would be nice to express "produces row set" with a function. But as far as I know, there is no way to do it except programmatically as I suggest above.