Skip to content

=$
|

  • Why upgrade PG?
  • explain.D.C
  • paste.D.C
  • Waiting for …
    • … PostgreSQL 14
    • … PostgreSQL 13
    • … PostgreSQL 12
    • … PostgreSQL 11
    • … PostgreSQL 10
    • … PostgreSQL 9.6
    • … PostgreSQL 9.5
    • … PostgreSQL 9.4
    • … PostgreSQL 9.3
    • … PostgreSQL 9.2
    • … PostgreSQL 9.1
    • … PostgreSQL 9.0
    • … PostgreSQL 8.5
    • … PostgreSQL 8.4
  • Projects
  • Contact

Tag: lag

Tips n’ tricks – rank on changes

I got asked this: having this table:

# SELECT * FROM a ORDER BY d;
 t | d  
---+----
 O |  1
 O |  2
 O |  3
 M |  4
 M |  5
 M |  6
 M |  7
 O |  8
 O |  9
 O | 10
 I | 11
 I | 12
 I | 13
(13 ROWS)

Is it possible to add “rank" column, that will increment whenever t changed?

Continue reading Tips n' tricks – rank on changes

Posted on 2010-05-13|Tags changes, count, lag, nullif, postgresql, rank, tnt, window functions|3 Comments on Tips n’ tricks – rank on changes

Search

Follow me

  • Comments RSS
  • Posts RSS

Popular Posts

  • How to run some tasks without user intervention, at specific times? 566 views | 2 comments
  • Are there limits to partition counts? 517 views | 2 comments
  • Waiting for PostgreSQL 14 – Add pg_stat_database counters for sessions and session time 218 views | 0 comments
  • Explaining the unexplainable – part 3 168 views | 0 comments
  • Explaining the unexplainable – part 2 148 views | 0 comments
  • CHAR(x) vs. VARCHAR(x) vs. VARCHAR vs. TEXT – UPDATED 2010-03-03 143 views | 0 comments
  • Why is UPSERT so complicated? 102 views | 0 comments
  • explain.depesz.com. 80 views | 0 comments
  • How much RAM is PostgreSQL using? 73 views | 0 comments
  • Why I’m not fan of uuid datatype 72 views | 0 comments

PostgreSQL

  • Documentation
  • Explain Analyze analyzer
  • IRC help channel
  • Mailing Lists search
  • PG Planet
  • PostgreSQL Home Page

About me

  • CPAN
  • GitLab
  • Linked In
  • Why upgrade PG?
  • explain.D.C
  • paste.D.C
  • Waiting for …
    • … PostgreSQL 14
    • … PostgreSQL 13
    • … PostgreSQL 12
    • … PostgreSQL 11
    • … PostgreSQL 10
    • … PostgreSQL 9.6
    • … PostgreSQL 9.5
    • … PostgreSQL 9.4
    • … PostgreSQL 9.3
    • … PostgreSQL 9.2
    • … PostgreSQL 9.1
    • … PostgreSQL 9.0
    • … PostgreSQL 8.5
    • … PostgreSQL 8.4
  • Projects
  • Contact