shlogg · Early preview
Judy @esproc_spl

Grouping PostgreSQL Tmp Table By Source_id And Event_date

Group PostgreSQL tmp table by source_id & sort by event_date. Add SERIES_ID to number sub-groups under each source_id using SPL code.

In PostgreSQL database, tmp table has two grouping fields – source_id and event_user. Group the table by source_id and sort each group by event_date, rows having same event_user value will form sub-groups in order, as shown below:

We want to add a computed column named SERIES_ID to number sub-groups under each source_id. The expected result is as follows:

Write the following SPL code:

A1: Retrieve data with a SQL statement and sort rows by source_id and event_date; SERIES_ID is eimpty.
A2: Group rows by comparing neighboring source_id values without sorting, and then group rows in each grou...