Reputation: 7101
We would like to trunate the string if it is longer than 100 and add ...
at the end.
We would like to do the whole operation on the DB to avoid network cost.
We use substring(s, 1, 100)
but how we can combine it with a function (most optimal function) to check and add the ...
if the string is more than 100 characters?
Upvotes: 0
Views: 621
Reputation: 1269953
You can use:
(case when length(s) < 100 then s
else substring(s, 1, 97) || '...'
end)
Upvotes: 2