2

I have simple select query like this SELECT str FROM table WHERE parent_id=5 Which will return thousands of rows. I need to count how many characters on selected rows. I thought 2 ways to do this.

1) Combine all rows to single string and use strlen function. (Looks simple but it will probably consume a lot of memory due to very long string)

2) Return size of selected rows in bytes and divide it to single char size according to used encoding. (I don't know how to calculate size of selected rows)

Which one will less load to server or reasonable way to do this? Thanks

kenarsuleyman
  • 920
  • 1
  • 6
  • 26

1 Answers1

3

Do you mean like below?

SELECT sum(char_length(str)) FROM table WHERE parent_id = 5
invisal
  • 11,075
  • 4
  • 33
  • 54
  • 1
    Don't ask for clarifications in the answer box – Masivuye Cokile May 24 '17 at 15:26
  • 1
    @MasivuyeCokile I think "Do you mean like below?" is usually used as a figure of speech, I use it all the time even when I know what I'm saying is what the OP is looking for... This is actually a very good answer. – David Wilkinson May 24 '17 at 15:28
  • Well, he answered my question with asking another question. I think i should accept it as answer. – kenarsuleyman May 24 '17 at 15:28
  • 2
    I usually do this for answer with not much explanation. It would be weird to answer with only code block. And I think it is more polite to ask if my answer is right, even I am 99% sure it is right :D – invisal May 24 '17 at 15:31