Skip to content

Commit

Permalink
Add compatibility for PostgreSQL 13
Browse files Browse the repository at this point in the history
  • Loading branch information
Vik Fearing committed May 27, 2020
1 parent 8ff348d commit 106e8fa
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 34 deletions.
50 changes: 20 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
dist: bionic

sudo: required

language: c

compiler:
- gcc

# run the testsuite on travis-ci.com
---
# versions to run on
env:
matrix:
- PG=12 COMPONENT=12
- PG=11
- PG=10
- PG=9.6
- PG=9.5
- PG_SUPPORTED_VERSIONS=9.5
- PG_SUPPORTED_VERSIONS=9.6
- PG_SUPPORTED_VERSIONS=10
- PG_SUPPORTED_VERSIONS=11
- PG_SUPPORTED_VERSIONS=12
- PG_SUPPORTED_VERSIONS=13

language: C
dist: bionic

before_install:
- sudo /etc/init.d/postgresql stop
- sudo apt-get -y --purge remove postgresql libpq-dev libpq5 postgresql-client-common postgresql-common
- sudo rm -rf /var/lib/postgresql
- |
if [ "$COMPONENT" ]; then
sudo sed -i -e "s/main/main $COMPONENT/" /etc/apt/sources.list.d/pgdg*.list
fi
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::="--force-confnew" ${PGREPO:+-t "$PGREPO"} install postgresql-${PG:?} postgresql-server-dev-${PG:?} postgresql-contrib-${PG:?}
- sudo apt-get update -qq

before_script:
- sudo -u postgres createuser -s "$USER"
install:
# upgrade postgresql-common for new apt.postgresql.org.sh
- sudo apt-get install -y postgresql-common
- sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -p -v $PG_SUPPORTED_VERSIONS -i
- sudo apt-get install -y postgresql-contrib-$PG_SUPPORTED_VERSIONS

script:
- make
- sudo make install
- make installcheck

after_script:
- cat regression.diffs || true
- pg_virtualenv make installcheck
- if test -s regression.diffs; then cat regression.diffs; fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Travis Build Status](https://api.travis-ci.com/xocolatl/periods.svg?branch=master)](https://travis-ci.com/xocolatl/periods)
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/xocolatl/periods?branch=master&svg=true)](https://ci.appveyor.com/project/xocolatl/periods)

*compatible 9.5–12*
*compatible 9.5–13*

This extension recreates the behavior defined in
[SQL:2016](https://www.iso.org/standard/63556.html) (originally in
Expand Down
13 changes: 10 additions & 3 deletions expected/periods.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
SELECT setting::integer < 130000 AS pre_13
FROM pg_settings WHERE name = 'server_version_num';
pre_13
--------
f
(1 row)

/* Basic period definitions with dates */
CREATE TABLE basic (val text, s date, e date);
TABLE periods.periods;
Expand Down Expand Up @@ -65,13 +72,13 @@ TABLE periods.periods;

/* Test constraints */
INSERT INTO basic (val, s, e) VALUES ('x', null, null); --fail
ERROR: null value in column "s" violates not-null constraint
ERROR: null value in column "s" of relation "basic" violates not-null constraint
DETAIL: Failing row contains (x, null, null).
INSERT INTO basic (val, s, e) VALUES ('x', '3000-01-01', null); --fail
ERROR: null value in column "e" violates not-null constraint
ERROR: null value in column "e" of relation "basic" violates not-null constraint
DETAIL: Failing row contains (x, 01-01-3000, null).
INSERT INTO basic (val, s, e) VALUES ('x', null, '1000-01-01'); --fail
ERROR: null value in column "s" violates not-null constraint
ERROR: null value in column "s" of relation "basic" violates not-null constraint
DETAIL: Failing row contains (x, null, 01-01-1000).
INSERT INTO basic (val, s, e) VALUES ('x', '3000-01-01', '1000-01-01'); --fail
ERROR: new row for relation "basic" violates check constraint "basic_bp_check"
Expand Down
99 changes: 99 additions & 0 deletions expected/periods_1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
SELECT setting::integer < 130000 AS pre_13
FROM pg_settings WHERE name = 'server_version_num';
pre_13
--------
t
(1 row)

/* Basic period definitions with dates */
CREATE TABLE basic (val text, s date, e date);
TABLE periods.periods;
table_name | period_name | start_column_name | end_column_name | range_type | bounds_check_constraint
------------+-------------+-------------------+-----------------+------------+-------------------------
(0 rows)

SELECT periods.add_period('basic', 'bp', 's', 'e');
add_period
------------
t
(1 row)

TABLE periods.periods;
table_name | period_name | start_column_name | end_column_name | range_type | bounds_check_constraint
------------+-------------+-------------------+-----------------+------------+-------------------------
basic | bp | s | e | daterange | basic_bp_check
(1 row)

SELECT periods.drop_period('basic', 'bp');
drop_period
-------------
t
(1 row)

TABLE periods.periods;
table_name | period_name | start_column_name | end_column_name | range_type | bounds_check_constraint
------------+-------------+-------------------+-----------------+------------+-------------------------
(0 rows)

SELECT periods.add_period('basic', 'bp', 's', 'e', bounds_check_constraint => 'c');
add_period
------------
t
(1 row)

TABLE periods.periods;
table_name | period_name | start_column_name | end_column_name | range_type | bounds_check_constraint
------------+-------------+-------------------+-----------------+------------+-------------------------
basic | bp | s | e | daterange | c
(1 row)

SELECT periods.drop_period('basic', 'bp', purge => true);
drop_period
-------------
t
(1 row)

TABLE periods.periods;
table_name | period_name | start_column_name | end_column_name | range_type | bounds_check_constraint
------------+-------------+-------------------+-----------------+------------+-------------------------
(0 rows)

SELECT periods.add_period('basic', 'bp', 's', 'e');
add_period
------------
t
(1 row)

TABLE periods.periods;
table_name | period_name | start_column_name | end_column_name | range_type | bounds_check_constraint
------------+-------------+-------------------+-----------------+------------+-------------------------
basic | bp | s | e | daterange | basic_bp_check
(1 row)

/* Test constraints */
INSERT INTO basic (val, s, e) VALUES ('x', null, null); --fail
ERROR: null value in column "s" violates not-null constraint
DETAIL: Failing row contains (x, null, null).
INSERT INTO basic (val, s, e) VALUES ('x', '3000-01-01', null); --fail
ERROR: null value in column "e" violates not-null constraint
DETAIL: Failing row contains (x, 01-01-3000, null).
INSERT INTO basic (val, s, e) VALUES ('x', null, '1000-01-01'); --fail
ERROR: null value in column "s" violates not-null constraint
DETAIL: Failing row contains (x, null, 01-01-1000).
INSERT INTO basic (val, s, e) VALUES ('x', '3000-01-01', '1000-01-01'); --fail
ERROR: new row for relation "basic" violates check constraint "basic_bp_check"
DETAIL: Failing row contains (x, 01-01-3000, 01-01-1000).
INSERT INTO basic (val, s, e) VALUES ('x', '1000-01-01', '3000-01-01'); --success
TABLE basic;
val | s | e
-----+------------+------------
x | 01-01-1000 | 01-01-3000
(1 row)

/* Test dropping the whole thing */
DROP TABLE basic;
TABLE periods.periods;
table_name | period_name | start_column_name | end_column_name | range_type | bounds_check_constraint
------------+-------------+-------------------+-----------------+------------+-------------------------
(0 rows)

4 changes: 4 additions & 0 deletions periods.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,11 @@ write_history(PG_FUNCTION_ARGS)
*
* See https://github.com/xocolatl/periods/issues/5
*/
#if (PG_VERSION_NUM < 130000)
map = convert_tuples_by_name(tupledesc, history_tupledesc, gettext_noop("could not convert row type"));
#else
map = convert_tuples_by_name(tupledesc, history_tupledesc);
#endif
if (map != NULL)
{
#if (PG_VERSION_NUM < 120000)
Expand Down
3 changes: 3 additions & 0 deletions sql/periods.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
SELECT setting::integer < 130000 AS pre_13
FROM pg_settings WHERE name = 'server_version_num';

/* Basic period definitions with dates */
CREATE TABLE basic (val text, s date, e date);
TABLE periods.periods;
Expand Down

0 comments on commit 106e8fa

Please sign in to comment.