Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learn PostgreSQL

You're reading from  Learn PostgreSQL

Product type Book
Published in Oct 2020
Publisher Packt
ISBN-13 9781838985288
Pages 650 pages
Edition 1st Edition
Languages
Concepts
Authors (2):
Luca Ferrari Luca Ferrari
Profile icon Luca Ferrari
Enrico Pirozzi Enrico Pirozzi
Profile icon Enrico Pirozzi
View More author details

Table of Contents (27) Chapters

Preface Section 1: Getting Started
Introduction to PostgreSQL Getting to Know Your Cluster Managing Users and Connections Section 2: Interacting with the Database
Basic Statements Advanced Statements Window Functions Server-Side Programming Triggers and Rules Partitioning Section 3: Administering the Cluster
Users, Roles, and Database Security Transactions, MVCC, WALs, and Checkpoints Extending the Database - the Extension Ecosystem Indexes and Performance Optimization Logging and Auditing Backup and Restore Configuration and Monitoring Section 4: Replication
Physical Replication Logical Replication Section 5: The PostegreSQL Ecosystem
Useful Tools and Extensions Toward PostgreSQL 13 Other Books You May Enjoy

Using advanced statement window functions

In this section, we will discuss advanced window functions in more detail, and we will explore some techniques that may be useful for carrying out more detailed data analysis.

Let's start with another way to write the same aggregate that we have described before:

forumdb=# select distinct category, count(*) over w1 
from posts
WINDOW w1 as (partition by category RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
order by category;
category | count
----------+-------
12 | 1
10 | 1
11 | 3
(3 rows)

What does RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW mean? They are the default conditions, known as the frame clause. This means that the data is partitioned, first by category, and then within the partition, the count is calculated by resetting the count every time the frame is changed.

The frame clause

In this section, we'll talk about the frame clause, which allows us to manage partitions in a different way. The frame...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}