From c314cbda75848941fde8c3030e0f829c96276aa9 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 18 Apr 2013 00:29:23 +0100 Subject: [PATCH 1/5] Check PostgreSQL version number as number in the makefile Not entirely happy about the solution but I like the uniform tests. --- Makefile | 12 +++---- bin/Makefile | 38 ++++++++-------------- bin/expected/init-extension.out | 3 ++ bin/expected/{init.out => init-legacy.out} | 0 bin/sql/init-extension.sql | 2 -- lib/Makefile | 11 ++++--- 6 files changed, 29 insertions(+), 37 deletions(-) create mode 100644 bin/expected/init-extension.out rename bin/expected/{init.out => init-legacy.out} (100%) diff --git a/Makefile b/Makefile index 1e43714..d74c55a 100644 --- a/Makefile +++ b/Makefile @@ -6,18 +6,18 @@ # Portions Copyright (c) 2012, The Reorg Development Team # -USE_PGXS = 1 -PG_CONFIG = pg_config -PGXS := $(shell $(PG_CONFIG) --pgxs) -include $(PGXS) +PG_CONFIG ?= pg_config SUBDIRS = bin lib # Pull out the version number from pg_config -VERSION = $(shell $(PG_CONFIG) --version | awk '{print $$2}') +VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') + +# version as a number, e.g. 9.1.4 -> 90104 +INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?(.*)/(\1*100+\2)*100+0\3/' | bc) # We support PostgreSQL 8.3 and later. -ifneq ($(shell echo $(VERSION) | grep -E "^7\.|^8\.[012]"),) +ifeq ($(shell echo $$(($(INTVERSION) < 80300))),1) $(error pg_repack requires PostgreSQL 8.3 or later. This is $(VERSION)) endif diff --git a/bin/Makefile b/bin/Makefile index 24ae1cd..d871e30 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -5,12 +5,24 @@ # Portions Copyright (c) 2011, Itagaki Takahiro # Portions Copyright (c) 2012, The Reorg Development Team # + +PG_CONFIG ?= pg_config + +# version as a number, e.g. 9.1.4 -> 90104 +VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') +INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?.*/(\1*100+\2)*100+0\3/' | bc) + SRCS = pg_repack.c pgut/pgut.c pgut/pgut-fe.c OBJS = $(SRCS:.c=.o) PROGRAM = pg_repack -REGRESS = init repack tablespace -EXTRA_CLEAN = sql/init-$(MAJORVERSION).sql sql/init.sql +ifeq ($(shell echo $$(($(INTVERSION) >= 90100))),1) +REGRESS = init-extension +else +REGRESS = init-legacy +endif + +REGRESS += repack tablespace # The version number of the program. It should be the same of the library. REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \ @@ -33,25 +45,3 @@ include $(PGXS) LIBS := $(filter-out -lxml2, $(LIBS)) LIBS := $(filter-out -lxslt, $(LIBS)) -ifndef MAJORVERSION -MAJORVERSION := $(basename $(VERSION)) -endif - -sql/init.sql: sql/init-$(MAJORVERSION).sql - cp sql/init-$(MAJORVERSION).sql sql/init.sql -expected/init.out: expected/init-$(MAJORVERSION).out - cp expected/init-$(MAJORVERSION).out expected/init.out -sql/init-8.3.sql: - cp sql/init-legacy.sql sql/init-8.3.sql -sql/init-8.4.sql: - cp sql/init-legacy.sql sql/init-8.4.sql -sql/init-9.0.sql: - cp sql/init-legacy.sql sql/init-9.0.sql -sql/init-9.1.sql: - cp sql/init-extension.sql sql/init-9.1.sql -sql/init-9.2.sql: - cp sql/init-extension.sql sql/init-9.2.sql -sql/init-9.3.sql: - cp sql/init-extension.sql sql/init-9.3.sql - -installcheck: sql/init.sql diff --git a/bin/expected/init-extension.out b/bin/expected/init-extension.out new file mode 100644 index 0000000..9f2e171 --- /dev/null +++ b/bin/expected/init-extension.out @@ -0,0 +1,3 @@ +SET client_min_messages = warning; +CREATE EXTENSION pg_repack; +RESET client_min_messages; diff --git a/bin/expected/init.out b/bin/expected/init-legacy.out similarity index 100% rename from bin/expected/init.out rename to bin/expected/init-legacy.out diff --git a/bin/sql/init-extension.sql b/bin/sql/init-extension.sql index 9da3176..9f2e171 100644 --- a/bin/sql/init-extension.sql +++ b/bin/sql/init-extension.sql @@ -1,5 +1,3 @@ SET client_min_messages = warning; -\set ECHO none CREATE EXTENSION pg_repack; -\set ECHO all RESET client_min_messages; diff --git a/lib/Makefile b/lib/Makefile index ca38f3a..8698163 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -6,7 +6,11 @@ # Portions Copyright (c) 2012, The Reorg Development Team # -PG_CONFIG = pg_config +PG_CONFIG ?= pg_config + +# version as a number, e.g. 9.1.4 -> 90104 +VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') +INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?.*/(\1*100+\2)*100+0\3/' | bc) EXTENSION = pg_repack MODULE_big = $(EXTENSION) @@ -20,10 +24,7 @@ REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \ PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION) # Support CREATE EXTENSION for PG >= 9.1 and a simple sql script for PG < 9.1 -HAVE_EXTENSION = $(shell $(PG_CONFIG) --version \ - | grep -qE " 8\.| 9\.0" && echo no || echo yes) - -ifeq ($(HAVE_EXTENSION),yes) +ifeq ($(shell echo $$(($(INTVERSION) >= 90100))),1) DATA_built = pg_repack--$(REPACK_VERSION).sql pg_repack.control else DATA_built = pg_repack.sql From dd06f2593038f37880f8a767cefc5dc7e0a74ed0 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 18 Apr 2013 00:34:44 +0100 Subject: [PATCH 2/5] Tests on COLLATE only run on PG versions supporting it --- bin/Makefile | 11 +++++++++ bin/expected/issue3.out | 53 +++++++++++++++++++++++++++++++++++++++++ bin/expected/repack.out | 53 ----------------------------------------- bin/sql/issue3.sql | 27 +++++++++++++++++++++ bin/sql/repack.sql | 28 ---------------------- 5 files changed, 91 insertions(+), 81 deletions(-) create mode 100644 bin/expected/issue3.out create mode 100644 bin/sql/issue3.sql diff --git a/bin/Makefile b/bin/Makefile index d871e30..04f38f2 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -16,6 +16,11 @@ SRCS = pg_repack.c pgut/pgut.c pgut/pgut-fe.c OBJS = $(SRCS:.c=.o) PROGRAM = pg_repack + +# +# Test suite +# + ifeq ($(shell echo $$(($(INTVERSION) >= 90100))),1) REGRESS = init-extension else @@ -24,6 +29,12 @@ endif REGRESS += repack tablespace +# This test depends on collate, not supported before 9.0 +ifeq ($(shell echo $$(($(INTVERSION) >= 90000))),1) +REGRESS += issue3 +endif + + # The version number of the program. It should be the same of the library. REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \ | sed -e 's/[ ]*"version":[ ]*"\(.*\)",/\1/') diff --git a/bin/expected/issue3.out b/bin/expected/issue3.out new file mode 100644 index 0000000..ee3e9a7 --- /dev/null +++ b/bin/expected/issue3.out @@ -0,0 +1,53 @@ +-- +-- pg_repack issue #3 +-- +CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC); +SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid); + get_order_by +----------------- + col1, col2 DESC +(1 row) + +\! pg_repack --dbname=contrib_regression --table=issue3_1 +INFO: repacking table "issue3_1" +CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops); +SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid); + get_order_by +--------------------------- + col1 DESC, col2 USING ~<~ +(1 row) + +\! pg_repack --dbname=contrib_regression --table=issue3_2 +INFO: repacking table "issue3_2" +CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC); +SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid); + get_order_by +---------------------- + col1 DESC, col2 DESC +(1 row) + +\! pg_repack --dbname=contrib_regression --table=issue3_3 +INFO: repacking table "issue3_3" +CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST); +SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid); + get_order_by +-------------------------------------------------- + col1 NULLS FIRST, col2 DESC USING ~<~ NULLS LAST +(1 row) + +\! pg_repack --dbname=contrib_regression --table=issue3_4 +INFO: repacking table "issue3_4" +CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC); +SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid); + get_order_by +-------------------------------------- + col1 DESC, col2 COLLATE "POSIX" DESC +(1 row) + +\! pg_repack --dbname=contrib_regression --table=issue3_5 +INFO: repacking table "issue3_5" diff --git a/bin/expected/repack.out b/bin/expected/repack.out index 76518f6..9bcc4b4 100644 --- a/bin/expected/repack.out +++ b/bin/expected/repack.out @@ -326,56 +326,3 @@ INFO: repacking table "tbl_pk_uk" \! pg_repack --dbname=contrib_regression --table=tbl_nn_puk WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys -- => WARNING --- --- pg_repack issue #3 --- -CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC); -SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid); - get_order_by ------------------ - col1, col2 DESC -(1 row) - -\! pg_repack --dbname=contrib_regression --table=issue3_1 -INFO: repacking table "issue3_1" -CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops); -SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid); - get_order_by ---------------------------- - col1 DESC, col2 USING ~<~ -(1 row) - -\! pg_repack --dbname=contrib_regression --table=issue3_2 -INFO: repacking table "issue3_2" -CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC); -SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid); - get_order_by ----------------------- - col1 DESC, col2 DESC -(1 row) - -\! pg_repack --dbname=contrib_regression --table=issue3_3 -INFO: repacking table "issue3_3" -CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST); -SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid); - get_order_by --------------------------------------------------- - col1 NULLS FIRST, col2 DESC USING ~<~ NULLS LAST -(1 row) - -\! pg_repack --dbname=contrib_regression --table=issue3_4 -INFO: repacking table "issue3_4" -CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC); -SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid); - get_order_by --------------------------------------- - col1 DESC, col2 COLLATE "POSIX" DESC -(1 row) - -\! pg_repack --dbname=contrib_regression --table=issue3_5 -INFO: repacking table "issue3_5" diff --git a/bin/sql/issue3.sql b/bin/sql/issue3.sql new file mode 100644 index 0000000..9065488 --- /dev/null +++ b/bin/sql/issue3.sql @@ -0,0 +1,27 @@ +-- +-- pg_repack issue #3 +-- +CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC); +SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid); +\! pg_repack --dbname=contrib_regression --table=issue3_1 + +CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops); +SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid); +\! pg_repack --dbname=contrib_regression --table=issue3_2 + +CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC); +SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid); +\! pg_repack --dbname=contrib_regression --table=issue3_3 + +CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST); +SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid); +\! pg_repack --dbname=contrib_regression --table=issue3_4 + +CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL); +CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC); +SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid); +\! pg_repack --dbname=contrib_regression --table=issue3_5 diff --git a/bin/sql/repack.sql b/bin/sql/repack.sql index c84a2a2..3a6f82f 100644 --- a/bin/sql/repack.sql +++ b/bin/sql/repack.sql @@ -187,31 +187,3 @@ CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; -- => OK \! pg_repack --dbname=contrib_regression --table=tbl_nn_puk -- => WARNING - --- --- pg_repack issue #3 --- -CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC); -SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid); -\! pg_repack --dbname=contrib_regression --table=issue3_1 - -CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops); -SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid); -\! pg_repack --dbname=contrib_regression --table=issue3_2 - -CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC); -SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid); -\! pg_repack --dbname=contrib_regression --table=issue3_3 - -CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST); -SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid); -\! pg_repack --dbname=contrib_regression --table=issue3_4 - -CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL); -CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC); -SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid); -\! pg_repack --dbname=contrib_regression --table=issue3_5 From 14c4d4653e48b97fddd6937c8a383db25a4a9b96 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 18 Apr 2013 01:10:22 +0100 Subject: [PATCH 3/5] Make the version number arith without using bc Not as available as I thought. Can't use the 0 prefix to make the 3rd number optional as $(()) parses is as octal, so only use the first 2 numbers. Also fixed collate test: not available on PG 9.0. --- Makefile | 13 ++++++++----- bin/Makefile | 10 +++++----- lib/Makefile | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index d74c55a..a10744e 100644 --- a/Makefile +++ b/Makefile @@ -8,20 +8,23 @@ PG_CONFIG ?= pg_config -SUBDIRS = bin lib - # Pull out the version number from pg_config VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') +ifeq ("$(VERSION)","") +$(error pg_config not found) +endif -# version as a number, e.g. 9.1.4 -> 90104 -INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?(.*)/(\1*100+\2)*100+0\3/' | bc) +# version as a number, e.g. 9.1.4 -> 901 +INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+).*/\1*100+\2/')))) # We support PostgreSQL 8.3 and later. -ifeq ($(shell echo $$(($(INTVERSION) < 80300))),1) +ifeq ($(shell echo $$(($(INTVERSION) < 803))),1) $(error pg_repack requires PostgreSQL 8.3 or later. This is $(VERSION)) endif +SUBDIRS = bin lib + all install installdirs uninstall distprep clean distclean maintainer-clean debug: @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir $@ || exit; \ diff --git a/bin/Makefile b/bin/Makefile index 04f38f2..1193e5f 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -8,9 +8,9 @@ PG_CONFIG ?= pg_config -# version as a number, e.g. 9.1.4 -> 90104 +# version as a number, e.g. 9.1.4 -> 901 VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') -INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?.*/(\1*100+\2)*100+0\3/' | bc) +INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+).*/\1*100+\2/')))) SRCS = pg_repack.c pgut/pgut.c pgut/pgut-fe.c OBJS = $(SRCS:.c=.o) @@ -21,7 +21,7 @@ PROGRAM = pg_repack # Test suite # -ifeq ($(shell echo $$(($(INTVERSION) >= 90100))),1) +ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1) REGRESS = init-extension else REGRESS = init-legacy @@ -29,8 +29,8 @@ endif REGRESS += repack tablespace -# This test depends on collate, not supported before 9.0 -ifeq ($(shell echo $$(($(INTVERSION) >= 90000))),1) +# This test depends on collate, not supported before 9.1 +ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1) REGRESS += issue3 endif diff --git a/lib/Makefile b/lib/Makefile index 8698163..1035742 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -8,9 +8,9 @@ PG_CONFIG ?= pg_config -# version as a number, e.g. 9.1.4 -> 90104 +# version as a number, e.g. 9.1.4 -> 901 VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') -INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?.*/(\1*100+\2)*100+0\3/' | bc) +INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+).*/\1*100+\2/')))) EXTENSION = pg_repack MODULE_big = $(EXTENSION) @@ -24,7 +24,7 @@ REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \ PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION) # Support CREATE EXTENSION for PG >= 9.1 and a simple sql script for PG < 9.1 -ifeq ($(shell echo $$(($(INTVERSION) >= 90100))),1) +ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1) DATA_built = pg_repack--$(REPACK_VERSION).sql pg_repack.control else DATA_built = pg_repack.sql From a2138b6d7d3a42cc7542c00d12fc03f29b23494e Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 18 Apr 2013 01:22:24 +0100 Subject: [PATCH 4/5] Ignore AFTER triggers sorting after z_repack_trigger They are not a problem, and they fore after the BEFORE trigger anyway. To be checked against more PostgreSQL versions. --- bin/expected/repack.out | 26 ++++++++++++++++++++++++++ bin/sql/repack.sql | 19 +++++++++++++++++++ lib/pg_repack.sql.in | 1 + 3 files changed, 46 insertions(+) diff --git a/bin/expected/repack.out b/bin/expected/repack.out index 9bcc4b4..1536b02 100644 --- a/bin/expected/repack.out +++ b/bin/expected/repack.out @@ -326,3 +326,29 @@ INFO: repacking table "tbl_pk_uk" \! pg_repack --dbname=contrib_regression --table=tbl_nn_puk WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys -- => WARNING +-- +-- Triggers handling +-- +CREATE FUNCTION trgtest() RETURNS trigger AS +$$BEGIN RETURN NEW; END$$ +LANGUAGE plpgsql; +CREATE TABLE trg1 (id integer PRIMARY KEY); +CREATE TRIGGER z_repack_triggeq BEFORE UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest(); +\! pg_repack --dbname=contrib_regression --table=trg1 +INFO: repacking table "trg1" +CREATE TABLE trg2 (id integer PRIMARY KEY); +CREATE TRIGGER z_repack_trigger BEFORE UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest(); +\! pg_repack --dbname=contrib_regression --table=trg2 +INFO: repacking table "trg2" +WARNING: the table "trg2" has already a trigger called "z_repack_trigger" +DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over. +CREATE TABLE trg3 (id integer PRIMARY KEY); +CREATE TRIGGER z_repack_trigges BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); +\! pg_repack --dbname=contrib_regression --table=trg3 +INFO: repacking table "trg3" +WARNING: trigger "z_repack_trigges" conflicting on table "trg3" +DETAIL: The trigger "z_repack_trigger" must be the last of the BEFORE triggers to fire on the table (triggers fire in alphabetical order). Please rename the trigger so that it sorts before "z_repack_trigger": you can use "ALTER TRIGGER z_repack_trigges ON trg3 RENAME TO newname". +CREATE TABLE trg4 (id integer PRIMARY KEY); +CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtest(); +\! pg_repack --dbname=contrib_regression --table=trg4 +INFO: repacking table "trg4" diff --git a/bin/sql/repack.sql b/bin/sql/repack.sql index 3a6f82f..e460c2d 100644 --- a/bin/sql/repack.sql +++ b/bin/sql/repack.sql @@ -187,3 +187,22 @@ CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; -- => OK \! pg_repack --dbname=contrib_regression --table=tbl_nn_puk -- => WARNING + +-- +-- Triggers handling +-- +CREATE FUNCTION trgtest() RETURNS trigger AS +$$BEGIN RETURN NEW; END$$ +LANGUAGE plpgsql; +CREATE TABLE trg1 (id integer PRIMARY KEY); +CREATE TRIGGER z_repack_triggeq BEFORE UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest(); +\! pg_repack --dbname=contrib_regression --table=trg1 +CREATE TABLE trg2 (id integer PRIMARY KEY); +CREATE TRIGGER z_repack_trigger BEFORE UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest(); +\! pg_repack --dbname=contrib_regression --table=trg2 +CREATE TABLE trg3 (id integer PRIMARY KEY); +CREATE TRIGGER z_repack_trigges BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest(); +\! pg_repack --dbname=contrib_regression --table=trg3 +CREATE TABLE trg4 (id integer PRIMARY KEY); +CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtest(); +\! pg_repack --dbname=contrib_regression --table=trg4 diff --git a/lib/pg_repack.sql.in b/lib/pg_repack.sql.in index d4c333a..d002872 100644 --- a/lib/pg_repack.sql.in +++ b/lib/pg_repack.sql.in @@ -219,6 +219,7 @@ CREATE FUNCTION repack.conflicted_triggers(oid) RETURNS SETOF name AS $$ SELECT tgname FROM pg_trigger WHERE tgrelid = $1 AND tgname >= 'z_repack_trigger' + AND (tgtype & 2) = 2 -- BEFORE trigger ORDER BY tgname; $$ LANGUAGE sql STABLE STRICT; From 54ba3c19cd3c995a703e886267e332929c591759 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 18 Apr 2013 01:32:05 +0100 Subject: [PATCH 5/5] Install plpgsql on test databases 8.3 and 8.4 Required by triggers tests --- bin/Makefile | 9 +++++++-- bin/expected/plpgsql.out | 1 + bin/sql/plpgsql.sql | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 bin/expected/plpgsql.out create mode 100644 bin/sql/plpgsql.sql diff --git a/bin/Makefile b/bin/Makefile index 1193e5f..c7226c8 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -22,9 +22,14 @@ PROGRAM = pg_repack # ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1) -REGRESS = init-extension +REGRESS := init-extension else -REGRESS = init-legacy +REGRESS := init-legacy +endif + +# plpgsql not available by default on pg < 9.0 +ifeq ($(shell echo $$(($(INTVERSION) < 900))),1) +REGRESS += plpgsql endif REGRESS += repack tablespace diff --git a/bin/expected/plpgsql.out b/bin/expected/plpgsql.out new file mode 100644 index 0000000..bc028fb --- /dev/null +++ b/bin/expected/plpgsql.out @@ -0,0 +1 @@ +CREATE LANGUAGE plpgsql; diff --git a/bin/sql/plpgsql.sql b/bin/sql/plpgsql.sql new file mode 100644 index 0000000..bc028fb --- /dev/null +++ b/bin/sql/plpgsql.sql @@ -0,0 +1 @@ +CREATE LANGUAGE plpgsql;