Skip to content

Commit 76a4085

Browse files
author
Vik Fearing
committed
initial commit
0 parents  commit 76a4085

13 files changed

+1210
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sql/* linguist-language=SQL
2+
expected/* linguist-detectable=false

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
test_current.sh

.travis.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# run the testsuite on travis-ci.com
2+
---
3+
# versions to run on
4+
env:
5+
- PG_SUPPORTED_VERSIONS=9.6
6+
- PG_SUPPORTED_VERSIONS=10
7+
- PG_SUPPORTED_VERSIONS=11
8+
- PG_SUPPORTED_VERSIONS=12
9+
- PG_SUPPORTED_VERSIONS=13
10+
11+
language: C
12+
dist: bionic
13+
14+
before_install:
15+
- sudo apt-get update -qq
16+
17+
install:
18+
# upgrade postgresql-common for new apt.postgresql.org.sh
19+
- sudo apt-get install -y postgresql-common
20+
- sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -p -v $PG_SUPPORTED_VERSIONS -i
21+
- sudo apt-get install -y postgresql-contrib-$PG_SUPPORTED_VERSIONS
22+
23+
script:
24+
- make
25+
- sudo make install
26+
- pg_virtualenv make installcheck
27+
- if test -s regression.diffs; then cat regression.diffs; fi

CODE_OF_CONDUCT.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This extension adheres to the official [PostgreSQL Community Code of
2+
Conduct](https://www.postgresql.org/about/policies/coc/). It is not
3+
reproduced here so that future modifications may take effect
4+
immediately.

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
PostgreSQL License
2+
3+
Copyright (c) 2019, The PostgreSQL Global Development Group (PGDG)
4+
5+
Permission to use, copy, modify, and distribute this software and its
6+
documentation for any purpose, without fee, and without a written agreement is
7+
hereby granted, provided that the above copyright notice and this paragraph
8+
and the following two paragraphs appear in all copies.
9+
10+
IN NO EVENT SHALL PGDG BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
11+
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
12+
OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF PGDG
13+
HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14+
15+
PGDG SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
16+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
18+
AND PGDG HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
19+
ENHANCEMENTS, OR MODIFICATIONS.

Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
MODULES = extra_window_functions
2+
EXTENSION = extra_window_functions
3+
DOCS = README.extra_window_functions
4+
5+
DATA = extra_window_functions--1.0.sql
6+
7+
REGRESS = regression
8+
9+
PG_CONFIG = pg_config
10+
PGXS := $(shell $(PG_CONFIG) --pgxs)
11+
include $(PGXS)

README.extra_window_functions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Extra Window Functions for PostgreSQL
2+
3+
[![License](https://img.shields.io/badge/license-PostgreSQL-blue)](https://www.postgresql.org/about/licence/)
4+
[![Code of Conduct](https://img.shields.io/badge/code%20of%20conduct-PostgreSQL-blueviolet)](https://www.postgresql.org/about/policies/coc/)
5+
6+
[![Travis Build Status](https://api.travis-ci.com/xocolatl/extra_window_functions.svg?branch=master)](https://travis-ci.com/xocolatl/extra_window_functions)
7+
8+
*compatible 9.6–13*
9+
10+
This extension provides additional window functions to PostgreSQL. Some of
11+
them provide SQL Standard functionality but without the SQL Standard grammar,
12+
others extend on the SQL Standard, and still others are novel and hopefully
13+
useful to someone.
14+
15+
## Simualating Standard SQL
16+
17+
The window functions `LEAD()`, `LAG()`, `FIRST_VALUE()`, `LAST_VALUE()`, and
18+
`NTH_VALUE()` can skip over null values. PostgreSQL does not implement the
19+
syntax required for that feature but this extension provides additional
20+
functions that give you the same behavior.
21+
22+
In addition to this, `NTH_VALUE()` can count from the start or the end of the
23+
window frame.
24+
25+
Despite these functions having long names, there isn't really any difference in
26+
length compared to the excessively verbose SQL Standard syntax.
27+
28+
```
29+
-- Standard SQL:
30+
NTH_VALUE(x, 3) FROM LAST IGNORE NULLS OVER w
31+
32+
-- This extension:
33+
nth_value_from_last_ignore_nulls(x, 3) OVER w
34+
```
35+
36+
## Extending Standard SQL
37+
38+
The functions `LEAD()` and `LAG()` accept a default value for when the
39+
requested row falls outside of the partition. However, the functions
40+
`FIRST_VALUE()`, `LAST_VALUE()`, and `NTH_VALUE()` do not have default values
41+
for when the requested row is not in the frame.
42+
43+
## Non-Standard Functions
44+
45+
This extension introduces a new partition-level window function `flip_flop()`
46+
and implements the
47+
"[flip floperator](https://en.wikipedia.org/wiki/Flip-flop_(programming))".
48+
49+
In the first variant, the function returns false until the expression given as
50+
an argument returns true. It then keeps returning true until expression is
51+
matched again. The second variant takes two expressions: the first to flip,
52+
the second to flop.

0 commit comments

Comments
 (0)