Reputation: 12807
I have an SQLite table where a column is of type 'text'. Each item in that column is program code. I want to find out how many lines each text item is. i.e. The following should be 3 lines:
program "help"
print "Help"
return.
Upvotes: 2
Views: 293
Reputation: 91207
You can count the \n
s by doing
LENGTH(TheColumn) - LENGTH(REPLACE(TheColumn, X'0A', '')) + 1
Upvotes: 1
Reputation: 24506
I don't think it's possible to do that only within SQLite as is. SQLite allows for user defined functions though, how that works depends on what programming language you're using.
Otherwise you could have a separate column that stores the line count, and update that with whichever language you're using when doing inserts / updates.
Upvotes: 0