Need some help with a query (uniq -c)
От | A B |
---|---|
Тема | Need some help with a query (uniq -c) |
Дата | |
Msg-id | k2gdbbf25901004121122wbd6daeccpe671b7a31e7be083@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Need some help with a query (uniq -c)
Re: Need some help with a query (uniq -c) |
Список | pgsql-general |
Hello! I have a table (think of it as a table of log messages) time | message ----------------------- 1 | a 2 | b 3 | b 4 | b 5 | a the three 'b' are the same message, so I would like to write a query that would give me a result that is similar to what the unix command "uniq -c" would give: first | message | last | count -------------------------------------- 1 | a | 1 | 1 2 | b | 4 | 3 <--- here it squeezes similar consecutive messages into a single row 5 | a | 5 | 1 How do I write such a command? I could of course write a plpgsql function that loops but that is not as interesting as finding out if this can be done in a single simple command. Perhaps it would be best to regularly delete neighbouring similar rows and keeping a "count" value would reduce the number of rows and make it more efficient if the query would be run many times and the number of duplicate messages would be large.
В списке pgsql-general по дате отправления: