mirror of
https://github.com/adjust/pg-base36.git
synced 2025-12-16 15:54:39 +00:00
Add HASHES, MERGES to equality operator (#15)
* Add HASHES, MERGES to equality operator
There is no good reason to disallow hash and merge on = it was just
not considered on the initial implementation.
The version migration however is kinda tricky, as postgres doesn't
allow to `ALTER OPERATOR` according to [hackers](321eed5f0f) because of query plan caching.
```
Other options cannot be changed, as it's not totally clear if cached plans
would need to be invalidated if one of the other options change.
```
An upgrade is probably not risky as it just adds more execution options to
the planer.
A downgrade however could result in executing a hash/merge join that actually isn't
allowed.
This might not be a problem as well as the previous version has all the needed
functionality to execute a hash/merge join (i.e. the underlying procedure didn't change).
* cleanup extension
get ride of dependency for ruby gem dumbo
cleanup tests
Turns out dumbo is not really helpful for this extension
and just creates noise and dependencies that are not really needed.
* Fix Postgres 10 test
---------
Co-authored-by: Artur Zakirov <zaartur@gmail.com>
This commit is contained in:
8
Gemfile
8
Gemfile
@@ -1,8 +0,0 @@
|
||||
# Gemfile
|
||||
source 'https://rubygems.org'
|
||||
gem 'dumbo', git: 'git@github.com:adjust/dumbo.git'
|
||||
gem 'pg'
|
||||
gem 'pry'
|
||||
gem 'rake', '12.3.3'
|
||||
gem 'rspec'
|
||||
gem 'activerecord', '6.1.7.1'
|
||||
73
Gemfile.lock
73
Gemfile.lock
@@ -1,73 +0,0 @@
|
||||
GIT
|
||||
remote: git@github.com:adjust/dumbo.git
|
||||
revision: e4a4821e86f0be26be8eb07f692610ba1b4bad12
|
||||
specs:
|
||||
dumbo (0.0.5)
|
||||
activerecord
|
||||
activesupport
|
||||
bundler (~> 1.5)
|
||||
erubis
|
||||
pg (> 0.17)
|
||||
rake
|
||||
rspec (~> 3.0.0)
|
||||
thor
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
activemodel (6.1.7.1)
|
||||
activesupport (= 6.1.7.1)
|
||||
activerecord (6.1.7.1)
|
||||
activemodel (= 6.1.7.1)
|
||||
activesupport (= 6.1.7.1)
|
||||
activesupport (6.1.7.1)
|
||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||
i18n (>= 1.6, < 2)
|
||||
minitest (>= 5.1)
|
||||
tzinfo (~> 2.0)
|
||||
zeitwerk (~> 2.3)
|
||||
coderay (1.1.0)
|
||||
concurrent-ruby (1.1.10)
|
||||
diff-lcs (1.2.5)
|
||||
erubis (2.7.0)
|
||||
i18n (1.12.0)
|
||||
concurrent-ruby (~> 1.0)
|
||||
method_source (0.8.2)
|
||||
minitest (5.17.0)
|
||||
pg (0.18.2)
|
||||
pry (0.10.1)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
rake (12.3.3)
|
||||
rspec (3.0.0)
|
||||
rspec-core (~> 3.0.0)
|
||||
rspec-expectations (~> 3.0.0)
|
||||
rspec-mocks (~> 3.0.0)
|
||||
rspec-core (3.0.4)
|
||||
rspec-support (~> 3.0.0)
|
||||
rspec-expectations (3.0.4)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.0.0)
|
||||
rspec-mocks (3.0.4)
|
||||
rspec-support (~> 3.0.0)
|
||||
rspec-support (3.0.4)
|
||||
slop (3.6.0)
|
||||
thor (0.20.0)
|
||||
tzinfo (2.0.5)
|
||||
concurrent-ruby (~> 1.0)
|
||||
zeitwerk (2.6.6)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord (= 6.1.7.1)
|
||||
dumbo!
|
||||
pg
|
||||
pry
|
||||
rake (= 12.3.3)
|
||||
rspec
|
||||
|
||||
BUNDLED WITH
|
||||
1.14.6
|
||||
3
Makefile
3
Makefile
@@ -7,7 +7,8 @@ MODULE_big = base36
|
||||
OBJS = $(patsubst %.c,%.o,$(wildcard src/*.c))
|
||||
TESTS = $(wildcard test/sql/*.sql)
|
||||
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
|
||||
REGRESS_OPTS = --inputdir=test
|
||||
REGRESS_OPTS = --inputdir=test \
|
||||
--load-extension=$(EXTENSION)
|
||||
include $(PGXS)
|
||||
|
||||
ifeq ($(shell test $(VERSION_NUM) -lt 90600; echo $$?),0)
|
||||
|
||||
11
base36--1.0.0--1.1.0.sql
Normal file
11
base36--1.0.0--1.1.0.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
UPDATE pg_catalog.pg_operator
|
||||
SET
|
||||
oprcanmerge = true,
|
||||
oprcanhash = true
|
||||
WHERE oprname = '=' AND oprleft = 'base36'::regtype AND oprright = 'base36'::regtype;
|
||||
|
||||
UPDATE pg_catalog.pg_operator
|
||||
SET
|
||||
oprcanmerge = true,
|
||||
oprcanhash = true
|
||||
WHERE oprname = '=' AND oprleft = 'bigbase36'::regtype AND oprright = 'bigbase36'::regtype;
|
||||
11
base36--1.1.0--1.0.0.sql
Normal file
11
base36--1.1.0--1.0.0.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
UPDATE pg_catalog.pg_operator
|
||||
SET
|
||||
oprcanmerge = false,
|
||||
oprcanhash = false
|
||||
WHERE oprname = '=' AND oprleft = 'base36'::regtype AND oprright = 'base36'::regtype;
|
||||
|
||||
UPDATE pg_catalog.pg_operator
|
||||
SET
|
||||
oprcanmerge = false,
|
||||
oprcanhash = false
|
||||
WHERE oprname = '=' AND oprleft = 'bigbase36'::regtype AND oprright = 'bigbase36'::regtype;
|
||||
395
base36--1.1.0.sql
Normal file
395
base36--1.1.0.sql
Normal file
@@ -0,0 +1,395 @@
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION base36" to load this file. \quit
|
||||
--source file sql/base36.sql
|
||||
CREATE FUNCTION base36_in(cstring)
|
||||
RETURNS base36
|
||||
AS '$libdir/base36'
|
||||
LANGUAGE C IMMUTABLE STRICT;
|
||||
|
||||
CREATE FUNCTION base36_out(base36)
|
||||
RETURNS cstring
|
||||
AS '$libdir/base36'
|
||||
LANGUAGE C IMMUTABLE STRICT;
|
||||
|
||||
CREATE FUNCTION base36_recv(internal)
|
||||
RETURNS base36 LANGUAGE internal IMMUTABLE AS 'int4recv';
|
||||
|
||||
CREATE FUNCTION base36_send(base36)
|
||||
RETURNS bytea LANGUAGE internal IMMUTABLE AS 'int4send';
|
||||
|
||||
CREATE TYPE base36 (
|
||||
INPUT = base36_in,
|
||||
OUTPUT = base36_out,
|
||||
RECEIVE = base36_recv,
|
||||
SEND = base36_send,
|
||||
LIKE = integer,
|
||||
CATEGORY = 'N'
|
||||
);
|
||||
COMMENT ON TYPE base36 IS 'int written in base36: [0-9a-z]+';
|
||||
|
||||
CREATE FUNCTION base36(text)
|
||||
RETURNS base36
|
||||
AS '$libdir/base36', 'base36_cast_from_text'
|
||||
LANGUAGE C IMMUTABLE STRICT;
|
||||
|
||||
CREATE FUNCTION text(base36)
|
||||
RETURNS text
|
||||
AS '$libdir/base36', 'base36_cast_to_text'
|
||||
LANGUAGE C IMMUTABLE STRICT;
|
||||
|
||||
CREATE CAST (text as base36) WITH FUNCTION base36(text) AS IMPLICIT;
|
||||
CREATE CAST (base36 as text) WITH FUNCTION text(base36);
|
||||
|
||||
CREATE CAST (integer as base36) WITHOUT FUNCTION AS IMPLICIT;
|
||||
CREATE CAST (base36 as integer) WITHOUT FUNCTION AS IMPLICIT;
|
||||
|
||||
CREATE FUNCTION base36_eq(base36, base36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int4eq';
|
||||
|
||||
CREATE FUNCTION base36_ne(base36, base36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int4ne';
|
||||
|
||||
CREATE FUNCTION base36_lt(base36, base36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int4lt';
|
||||
|
||||
CREATE FUNCTION base36_le(base36, base36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int4le';
|
||||
|
||||
CREATE FUNCTION base36_gt(base36, base36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int4gt';
|
||||
|
||||
CREATE FUNCTION base36_ge(base36, base36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int4ge';
|
||||
|
||||
CREATE FUNCTION base36_cmp(base36, base36)
|
||||
RETURNS integer LANGUAGE internal IMMUTABLE AS 'btint4cmp';
|
||||
|
||||
CREATE FUNCTION hash_base36(base36)
|
||||
RETURNS integer LANGUAGE internal IMMUTABLE AS 'hashint4';
|
||||
|
||||
DO $$
|
||||
DECLARE version_num integer;
|
||||
BEGIN
|
||||
SELECT current_setting('server_version_num') INTO STRICT version_num;
|
||||
IF version_num > 90600 THEN
|
||||
EXECUTE $E$ ALTER FUNCTION base36_in(cstring) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_out(base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_recv(internal) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_send(base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36(text) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION text(base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_eq(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_ne(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_lt(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_le(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_gt(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_ge(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_cmp(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION hash_base36(base36) PARALLEL SAFE $E$;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CREATE OPERATOR = (
|
||||
LEFTARG = base36,
|
||||
RIGHTARG = base36,
|
||||
PROCEDURE = base36_eq,
|
||||
COMMUTATOR = '=',
|
||||
NEGATOR = '<>',
|
||||
RESTRICT = eqsel,
|
||||
JOIN = eqjoinsel,
|
||||
HASHES, MERGES
|
||||
);
|
||||
COMMENT ON OPERATOR =(base36, base36) IS 'equals?';
|
||||
|
||||
CREATE OPERATOR <> (
|
||||
LEFTARG = base36,
|
||||
RIGHTARG = base36,
|
||||
PROCEDURE = base36_ne,
|
||||
COMMUTATOR = '<>',
|
||||
NEGATOR = '=',
|
||||
RESTRICT = neqsel,
|
||||
JOIN = neqjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR <>(base36, base36) IS 'not equals?';
|
||||
|
||||
CREATE OPERATOR < (
|
||||
LEFTARG = base36,
|
||||
RIGHTARG = base36,
|
||||
PROCEDURE = base36_lt,
|
||||
COMMUTATOR = > ,
|
||||
NEGATOR = >= ,
|
||||
RESTRICT = scalarltsel,
|
||||
JOIN = scalarltjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR <(base36, base36) IS 'less-than';
|
||||
|
||||
CREATE OPERATOR <= (
|
||||
LEFTARG = base36,
|
||||
RIGHTARG = base36,
|
||||
PROCEDURE = base36_le,
|
||||
COMMUTATOR = >= ,
|
||||
NEGATOR = > ,
|
||||
RESTRICT = scalarltsel,
|
||||
JOIN = scalarltjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR <=(base36, base36) IS 'less-than-or-equal';
|
||||
|
||||
CREATE OPERATOR > (
|
||||
LEFTARG = base36,
|
||||
RIGHTARG = base36,
|
||||
PROCEDURE = base36_gt,
|
||||
COMMUTATOR = < ,
|
||||
NEGATOR = <= ,
|
||||
RESTRICT = scalargtsel,
|
||||
JOIN = scalargtjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR >(base36, base36) IS 'greater-than';
|
||||
|
||||
CREATE OPERATOR >= (
|
||||
LEFTARG = base36,
|
||||
RIGHTARG = base36,
|
||||
PROCEDURE = base36_ge,
|
||||
COMMUTATOR = <= ,
|
||||
NEGATOR = < ,
|
||||
RESTRICT = scalargtsel,
|
||||
JOIN = scalargtjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR >=(base36, base36) IS 'greater-than-or-equal';
|
||||
|
||||
CREATE OPERATOR CLASS btree_base36_ops
|
||||
DEFAULT FOR TYPE base36 USING btree
|
||||
AS
|
||||
OPERATOR 1 < ,
|
||||
OPERATOR 2 <= ,
|
||||
OPERATOR 3 = ,
|
||||
OPERATOR 4 >= ,
|
||||
OPERATOR 5 > ,
|
||||
FUNCTION 1 base36_cmp(base36, base36);
|
||||
|
||||
CREATE OPERATOR CLASS hash_base36_ops
|
||||
DEFAULT FOR TYPE base36 USING hash AS
|
||||
OPERATOR 1 = ,
|
||||
FUNCTION 1 hash_base36(base36);
|
||||
|
||||
--source file sql/bigbase36.sql
|
||||
CREATE FUNCTION bigbase36_in(cstring)
|
||||
RETURNS bigbase36
|
||||
AS '$libdir/base36'
|
||||
LANGUAGE C IMMUTABLE STRICT;
|
||||
|
||||
CREATE FUNCTION bigbase36_out(bigbase36)
|
||||
RETURNS cstring
|
||||
AS '$libdir/base36'
|
||||
LANGUAGE C IMMUTABLE STRICT;
|
||||
|
||||
CREATE FUNCTION bigbase36_recv(internal)
|
||||
RETURNS bigbase36 LANGUAGE internal IMMUTABLE AS 'int8recv';
|
||||
|
||||
CREATE FUNCTION bigbase36_send(bigbase36)
|
||||
RETURNS bytea LANGUAGE internal IMMUTABLE AS 'int8send';
|
||||
|
||||
CREATE TYPE bigbase36 (
|
||||
INPUT = bigbase36_in,
|
||||
OUTPUT = bigbase36_out,
|
||||
RECEIVE = bigbase36_recv,
|
||||
SEND = bigbase36_send,
|
||||
LIKE = bigint,
|
||||
CATEGORY = 'N'
|
||||
);
|
||||
COMMENT ON TYPE bigbase36 IS 'bigint written in bigbase36: [0-9a-z]+';
|
||||
|
||||
CREATE FUNCTION bigbase36(text)
|
||||
RETURNS bigbase36
|
||||
AS '$libdir/base36', 'bigbase36_cast_from_text'
|
||||
LANGUAGE C IMMUTABLE STRICT;
|
||||
|
||||
CREATE FUNCTION text(bigbase36)
|
||||
RETURNS text
|
||||
AS '$libdir/base36', 'bigbase36_cast_to_text'
|
||||
LANGUAGE C IMMUTABLE STRICT;
|
||||
|
||||
CREATE CAST (text as bigbase36) WITH FUNCTION bigbase36(text) AS IMPLICIT;
|
||||
CREATE CAST (bigbase36 as text) WITH FUNCTION text(bigbase36);
|
||||
|
||||
CREATE CAST (bigint as bigbase36) WITHOUT FUNCTION AS IMPLICIT;
|
||||
CREATE CAST (bigbase36 as bigint) WITHOUT FUNCTION AS IMPLICIT;
|
||||
|
||||
CREATE FUNCTION bigbase36_eq(bigbase36, bigbase36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int8eq';
|
||||
|
||||
CREATE FUNCTION bigbase36_ne(bigbase36, bigbase36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int8ne';
|
||||
|
||||
CREATE FUNCTION bigbase36_lt(bigbase36, bigbase36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int8lt';
|
||||
|
||||
CREATE FUNCTION bigbase36_le(bigbase36, bigbase36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int8le';
|
||||
|
||||
CREATE FUNCTION bigbase36_gt(bigbase36, bigbase36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int8gt';
|
||||
|
||||
CREATE FUNCTION bigbase36_ge(bigbase36, bigbase36)
|
||||
RETURNS boolean LANGUAGE internal IMMUTABLE AS 'int8ge';
|
||||
|
||||
CREATE FUNCTION bigbase36_cmp(bigbase36, bigbase36)
|
||||
RETURNS integer LANGUAGE internal IMMUTABLE AS 'btint8cmp';
|
||||
|
||||
CREATE FUNCTION hash_bigbase36(bigbase36)
|
||||
RETURNS integer LANGUAGE internal IMMUTABLE AS 'hashint8';
|
||||
|
||||
DO $$
|
||||
DECLARE version_num integer;
|
||||
BEGIN
|
||||
SELECT current_setting('server_version_num') INTO STRICT version_num;
|
||||
IF version_num > 90600 THEN
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_in(cstring) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_out(bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_recv(internal) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_send(bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36(text) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION text(bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_eq(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_ne(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_lt(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_le(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_gt(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_ge(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_cmp(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION hash_bigbase36(bigbase36) PARALLEL SAFE $E$;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CREATE OPERATOR = (
|
||||
LEFTARG = bigbase36,
|
||||
RIGHTARG = bigbase36,
|
||||
PROCEDURE = bigbase36_eq,
|
||||
COMMUTATOR = '=',
|
||||
NEGATOR = '<>',
|
||||
RESTRICT = eqsel,
|
||||
JOIN = eqjoinsel,
|
||||
HASHES, MERGES
|
||||
);
|
||||
COMMENT ON OPERATOR =(bigbase36, bigbase36) IS 'equals?';
|
||||
|
||||
CREATE OPERATOR <> (
|
||||
LEFTARG = bigbase36,
|
||||
RIGHTARG = bigbase36,
|
||||
PROCEDURE = bigbase36_ne,
|
||||
COMMUTATOR = '<>',
|
||||
NEGATOR = '=',
|
||||
RESTRICT = neqsel,
|
||||
JOIN = neqjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR <>(bigbase36, bigbase36) IS 'not equals?';
|
||||
|
||||
CREATE OPERATOR < (
|
||||
LEFTARG = bigbase36,
|
||||
RIGHTARG = bigbase36,
|
||||
PROCEDURE = bigbase36_lt,
|
||||
COMMUTATOR = > ,
|
||||
NEGATOR = >= ,
|
||||
RESTRICT = scalarltsel,
|
||||
JOIN = scalarltjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR <(bigbase36, bigbase36) IS 'less-than';
|
||||
|
||||
CREATE OPERATOR <= (
|
||||
LEFTARG = bigbase36,
|
||||
RIGHTARG = bigbase36,
|
||||
PROCEDURE = bigbase36_le,
|
||||
COMMUTATOR = >= ,
|
||||
NEGATOR = > ,
|
||||
RESTRICT = scalarltsel,
|
||||
JOIN = scalarltjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR <=(bigbase36, bigbase36) IS 'less-than-or-equal';
|
||||
|
||||
CREATE OPERATOR > (
|
||||
LEFTARG = bigbase36,
|
||||
RIGHTARG = bigbase36,
|
||||
PROCEDURE = bigbase36_gt,
|
||||
COMMUTATOR = < ,
|
||||
NEGATOR = <= ,
|
||||
RESTRICT = scalargtsel,
|
||||
JOIN = scalargtjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR >(bigbase36, bigbase36) IS 'greater-than';
|
||||
|
||||
CREATE OPERATOR >= (
|
||||
LEFTARG = bigbase36,
|
||||
RIGHTARG = bigbase36,
|
||||
PROCEDURE = bigbase36_ge,
|
||||
COMMUTATOR = <= ,
|
||||
NEGATOR = < ,
|
||||
RESTRICT = scalargtsel,
|
||||
JOIN = scalargtjoinsel
|
||||
);
|
||||
COMMENT ON OPERATOR >=(bigbase36, bigbase36) IS 'greater-than-or-equal';
|
||||
|
||||
CREATE OPERATOR CLASS btree_bigbase36_ops
|
||||
DEFAULT FOR TYPE bigbase36 USING btree
|
||||
AS
|
||||
OPERATOR 1 < ,
|
||||
OPERATOR 2 <= ,
|
||||
OPERATOR 3 = ,
|
||||
OPERATOR 4 >= ,
|
||||
OPERATOR 5 > ,
|
||||
FUNCTION 1 bigbase36_cmp(bigbase36, bigbase36);
|
||||
|
||||
CREATE OPERATOR CLASS hash_bigbase36_ops
|
||||
DEFAULT FOR TYPE bigbase36 USING hash AS
|
||||
OPERATOR 1 = ,
|
||||
FUNCTION 1 hash_bigbase36(bigbase36);
|
||||
|
||||
--source file sql/parallel.sql
|
||||
|
||||
DO $$
|
||||
DECLARE version_num integer;
|
||||
BEGIN
|
||||
SELECT current_setting('server_version_num') INTO STRICT version_num;
|
||||
IF version_num > 90600 THEN
|
||||
EXECUTE $E$ ALTER FUNCTION base36_in(cstring) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_out(base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_recv(internal) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_send(base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36(text) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION text(base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_eq(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_ne(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_lt(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_le(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_gt(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_ge(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION base36_cmp(base36, base36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION hash_base36(base36) PARALLEL SAFE $E$;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
DECLARE version_num integer;
|
||||
BEGIN
|
||||
SELECT current_setting('server_version_num') INTO STRICT version_num;
|
||||
IF version_num > 90600 THEN
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_in(cstring) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_out(bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_recv(internal) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_send(bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36(text) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION text(bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_eq(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_ne(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_lt(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_le(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_gt(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_ge(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION bigbase36_cmp(bigbase36, bigbase36) PARALLEL SAFE $E$;
|
||||
EXECUTE $E$ ALTER FUNCTION hash_bigbase36(bigbase36) PARALLEL SAFE $E$;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# base36 extension
|
||||
comment = 'Integer Base36 types'
|
||||
default_version = '1.0.0'
|
||||
default_version = '1.1.0'
|
||||
relocatable = true
|
||||
requires = ''
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'base36' do
|
||||
before do
|
||||
install_extension
|
||||
end
|
||||
|
||||
describe 'conversion' do
|
||||
it 'should encode integer' do
|
||||
query('SELECT 120::base36').should match '3c'
|
||||
end
|
||||
|
||||
it 'should decode text' do
|
||||
query("SELECT '3c'::base36::int").should match '120'
|
||||
end
|
||||
|
||||
it 'should error to big values' do
|
||||
expect{query("SELECT '3caaaaaaaaaaaaa'::base36::bigint")}.to throw_error 'value "3caaaaaaaaaaaaa" is out of range for type base36'
|
||||
end
|
||||
|
||||
it 'should cast big base36 values' do
|
||||
query("SELECT 'zik0zj'::base36::int").should match 2147483647
|
||||
end
|
||||
|
||||
it 'should cast big int values' do
|
||||
query("SELECT 2147483647::base36").should match 'zik0zj'
|
||||
end
|
||||
|
||||
it 'should error to big values' do
|
||||
expect{query("SELECT 'zik0zk'::base36::int")}.to throw_error 'value "zik0zk" is out of range for type base36'
|
||||
end
|
||||
|
||||
it 'should error invalid values' do
|
||||
expect{query("SELECT '3&'::base36::bigint")}.to throw_error 'value "&" is not a valid digit for type base36'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'comparison' do
|
||||
it 'should compare using >' do
|
||||
query("SELECT 'a'::base36 > 'b'::base36").should match 'f'
|
||||
end
|
||||
|
||||
it 'should compare using <' do
|
||||
query("SELECT 'a'::base36 < 'b'::base36").should match 't'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'negative values' do
|
||||
it 'should convert from base36' do
|
||||
query("SELECT '-zik0zj'::base36::int").should match -2147483647
|
||||
end
|
||||
|
||||
it 'should convert from ints' do
|
||||
query("SELECT '-2147483647'::integer::base36").should match '-zik0zj'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,57 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'bigbase36' do
|
||||
before do
|
||||
install_extension
|
||||
end
|
||||
|
||||
describe 'conversion' do
|
||||
it 'should encode integer' do
|
||||
query('SELECT 120::bigint::bigbase36').should match '3c'
|
||||
end
|
||||
|
||||
it 'should decode text' do
|
||||
query("SELECT '3c'::bigbase36::bigint").should match '120'
|
||||
end
|
||||
|
||||
it 'should error to big values' do
|
||||
expect{query("SELECT '3caaaaaaaaaaaaa'::bigbase36::bigint")}.to throw_error 'value "3caaaaaaaaaaaaa" is out of range for type bigbase36'
|
||||
end
|
||||
|
||||
it 'should cast big bigbase36 values' do
|
||||
query("SELECT '1y2p0ij32e8e7'::bigbase36::bigint").should match 9223372036854775807
|
||||
end
|
||||
|
||||
it 'should cast big bigint values' do
|
||||
query("SELECT 9223372036854775807::bigbase36").should match '1y2p0ij32e8e7'
|
||||
end
|
||||
|
||||
it 'should error to big values' do
|
||||
expect{query("SELECT '1y2p0ij32e8e8'::bigbase36::bigint")}.to throw_error 'value "1y2p0ij32e8e8" is out of range for type bigbase36'
|
||||
end
|
||||
|
||||
it 'should error invalid values' do
|
||||
expect{query("SELECT '3&'::bigbase36::bigint")}.to throw_error 'value "&" is not a valid digit for type bigbase36'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'comparison' do
|
||||
it 'should compare using >' do
|
||||
query("SELECT 'a'::bigbase36 > 'b'::bigbase36").should match 'f'
|
||||
end
|
||||
|
||||
it 'should compare using <' do
|
||||
query("SELECT 'a'::bigbase36 < 'b'::bigbase36").should match 't'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'negative values' do
|
||||
it 'should convert from base36' do
|
||||
query("SELECT '-zik0zj'::bigbase36::bigint").should match -2147483647
|
||||
end
|
||||
|
||||
it 'should convert from ints' do
|
||||
query("SELECT '-2147483647'::bigint::bigbase36").should match '-zik0zj'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,41 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'base36 binary' do
|
||||
before do
|
||||
install_extension
|
||||
end
|
||||
|
||||
it "should copy data binary from country" do
|
||||
query("CREATE TABLE before (a base36)")
|
||||
query("INSERT INTO before VALUES ('aa'), ('-aa'), ('zik0zj'), ('-zik0zj'), ('0')")
|
||||
query("CREATE TABLE after (a base36)")
|
||||
query("COPY before TO '/tmp/tst' WITH (FORMAT binary)")
|
||||
query("COPY after FROM '/tmp/tst' WITH (FORMAT binary)")
|
||||
query("SELECT * FROM after").should match \
|
||||
['aa'],
|
||||
['-aa'],
|
||||
['zik0zj'],
|
||||
['-zik0zj'],
|
||||
['0']
|
||||
end
|
||||
end
|
||||
|
||||
describe 'bigbase36 binary' do
|
||||
before do
|
||||
install_extension
|
||||
end
|
||||
|
||||
it "should copy data binary from country" do
|
||||
query("CREATE TABLE before (a bigbase36)")
|
||||
query("INSERT INTO before VALUES ('aa'), ('-aa'), ('1y2p0ij32e8e7'), ('-1y2p0ij32e8e7'), ('0')")
|
||||
query("CREATE TABLE after (a bigbase36)")
|
||||
query("COPY before TO '/tmp/tst' WITH (FORMAT binary)")
|
||||
query("COPY after FROM '/tmp/tst' WITH (FORMAT binary)")
|
||||
query("SELECT * FROM after").should match \
|
||||
['aa'],
|
||||
['-aa'],
|
||||
['1y2p0ij32e8e7'],
|
||||
['-1y2p0ij32e8e7'],
|
||||
['0']
|
||||
end
|
||||
end
|
||||
@@ -1,34 +0,0 @@
|
||||
require 'rubygems'
|
||||
require 'dumbo/test'
|
||||
|
||||
ENV['DUMBO_ENV'] ||= 'test'
|
||||
require File.expand_path('../../config/boot', __FILE__)
|
||||
|
||||
require 'dumbo/test/silence_unknown_oid'
|
||||
|
||||
ActiveRecord::Base.logger.level = 0 if ActiveRecord::Base.logger
|
||||
|
||||
Dir.glob('spec/support/**/*.rb').each { |f| require f }
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.fail_fast = false
|
||||
config.order = 'random'
|
||||
config.filter_run focus: true
|
||||
config.run_all_when_everything_filtered = true
|
||||
config.expect_with :rspec do |c|
|
||||
c.syntax = [:should, :expect]
|
||||
end
|
||||
|
||||
# wrap test in transactions
|
||||
config.around(:each) do |example|
|
||||
ActiveRecord::Base.transaction do
|
||||
example.run
|
||||
fail ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
config.include(Dumbo::Test::Helper)
|
||||
config.include(Dumbo::Matchers)
|
||||
end
|
||||
|
||||
require 'dumbo/test/regression_helper' if ENV['DUMBO_REGRESSION']
|
||||
@@ -1,31 +0,0 @@
|
||||
module ExtensionHelper
|
||||
def install_testing_extension
|
||||
system <<-CMD
|
||||
(
|
||||
mkdir -p #{spec_root}/dumbo_sample_runtime && \
|
||||
cp -R #{spec_root}/dumbo_sample/ #{spec_root}/dumbo_sample_runtime
|
||||
cd #{spec_root}/dumbo_sample_runtime && \
|
||||
make clean && \
|
||||
make && \
|
||||
make install
|
||||
) 1> /dev/null
|
||||
CMD
|
||||
end
|
||||
|
||||
def uninstall_testing_extension
|
||||
system <<-CMD
|
||||
(
|
||||
cd #{spec_root}/dumbo_sample_runtime && \
|
||||
make clean && \
|
||||
make uninstall && \
|
||||
rm -rf #{spec_root}/dumbo_sample_runtime
|
||||
) 1> /dev/null
|
||||
CMD
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def spec_root
|
||||
File.join(File.dirname(__FILE__), '..')
|
||||
end
|
||||
end
|
||||
@@ -94,7 +94,8 @@ CREATE OPERATOR = (
|
||||
COMMUTATOR = '=',
|
||||
NEGATOR = '<>',
|
||||
RESTRICT = eqsel,
|
||||
JOIN = eqjoinsel
|
||||
JOIN = eqjoinsel,
|
||||
HASHES, MERGES
|
||||
);
|
||||
COMMENT ON OPERATOR =(base36, base36) IS 'equals?';
|
||||
|
||||
|
||||
@@ -94,7 +94,8 @@ CREATE OPERATOR = (
|
||||
COMMUTATOR = '=',
|
||||
NEGATOR = '<>',
|
||||
RESTRICT = eqsel,
|
||||
JOIN = eqjoinsel
|
||||
JOIN = eqjoinsel,
|
||||
HASHES, MERGES
|
||||
);
|
||||
COMMENT ON OPERATOR =(bigbase36, bigbase36) IS 'equals?';
|
||||
|
||||
|
||||
@@ -1,93 +1,71 @@
|
||||
BEGIN;
|
||||
-- base36 conversion should encode integer;
|
||||
-- ./spec/base36_spec.rb:9;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 120::base36;
|
||||
base36
|
||||
--------
|
||||
3c
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should decode text;
|
||||
-- ./spec/base36_spec.rb:13;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3c'::base36::int;
|
||||
int4
|
||||
------
|
||||
120
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should error to big values;
|
||||
-- ./spec/base36_spec.rb:17;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3caaaaaaaaaaaaa'::base36::bigint;
|
||||
ERROR: value "3caaaaaaaaaaaaa" is out of range for type base36
|
||||
LINE 1: SELECT '3caaaaaaaaaaaaa'::base36::bigint;
|
||||
^
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should cast big base36 values;
|
||||
-- ./spec/base36_spec.rb:21;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'zik0zj'::base36::int;
|
||||
int4
|
||||
------------
|
||||
2147483647
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should cast big int values;
|
||||
-- ./spec/base36_spec.rb:25;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 2147483647::base36;
|
||||
base36
|
||||
--------
|
||||
zik0zj
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should error to big values;
|
||||
-- ./spec/base36_spec.rb:29;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'zik0zk'::base36::int;
|
||||
ERROR: value "zik0zk" is out of range for type base36
|
||||
LINE 1: SELECT 'zik0zk'::base36::int;
|
||||
^
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should error invalid values;
|
||||
-- ./spec/base36_spec.rb:33;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3&'::base36::bigint;
|
||||
ERROR: value "&" is not a valid digit for type base36
|
||||
LINE 1: SELECT '3&'::base36::bigint;
|
||||
^
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 comparison should compare using >;
|
||||
-- ./spec/base36_spec.rb:39;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'a'::base36 > 'b'::base36;
|
||||
?column?
|
||||
----------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 comparison should compare using <;
|
||||
-- ./spec/base36_spec.rb:43;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'a'::base36 < 'b'::base36;
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
-- base36 negative values should convert from base36;
|
||||
SELECT '-zik0zj'::base36::int;
|
||||
int4
|
||||
-------------
|
||||
-2147483647
|
||||
(1 row)
|
||||
|
||||
-- base36 negative values should convert from ints;
|
||||
SELECT '-2147483647'::integer::base36;
|
||||
base36
|
||||
---------
|
||||
-zik0zj
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -1,93 +1,71 @@
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should encode integer;
|
||||
-- ./spec/bigbase36_spec.rb:9;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 120::bigint::bigbase36;
|
||||
bigbase36
|
||||
-----------
|
||||
3c
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should decode text;
|
||||
-- ./spec/bigbase36_spec.rb:13;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3c'::bigbase36::bigint;
|
||||
int8
|
||||
------
|
||||
120
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should error to big values;
|
||||
-- ./spec/bigbase36_spec.rb:17;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3caaaaaaaaaaaaa'::bigbase36::bigint;
|
||||
ERROR: value "3caaaaaaaaaaaaa" is out of range for type bigbase36
|
||||
LINE 1: SELECT '3caaaaaaaaaaaaa'::bigbase36::bigint;
|
||||
^
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should cast big bigbase36 values;
|
||||
-- ./spec/bigbase36_spec.rb:21;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '1y2p0ij32e8e7'::bigbase36::bigint;
|
||||
int8
|
||||
---------------------
|
||||
9223372036854775807
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should cast big bigint values;
|
||||
-- ./spec/bigbase36_spec.rb:25;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 9223372036854775807::bigbase36;
|
||||
bigbase36
|
||||
---------------
|
||||
1y2p0ij32e8e7
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should error to big values;
|
||||
-- ./spec/bigbase36_spec.rb:29;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '1y2p0ij32e8e8'::bigbase36::bigint;
|
||||
ERROR: value "1y2p0ij32e8e8" is out of range for type bigbase36
|
||||
LINE 1: SELECT '1y2p0ij32e8e8'::bigbase36::bigint;
|
||||
^
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should error invalid values;
|
||||
-- ./spec/bigbase36_spec.rb:33;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3&'::bigbase36::bigint;
|
||||
ERROR: value "&" is not a valid digit for type bigbase36
|
||||
LINE 1: SELECT '3&'::bigbase36::bigint;
|
||||
^
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 comparison should compare using >;
|
||||
-- ./spec/bigbase36_spec.rb:39;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'a'::bigbase36 > 'b'::bigbase36;
|
||||
?column?
|
||||
----------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 comparison should compare using <;
|
||||
-- ./spec/bigbase36_spec.rb:43;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'a'::bigbase36 < 'b'::bigbase36;
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
ROLLBACK;
|
||||
-- bigbase36 negative values should convert from base36;
|
||||
SELECT '-zik0zj'::bigbase36::bigint;
|
||||
int8
|
||||
-------------
|
||||
-2147483647
|
||||
(1 row)
|
||||
|
||||
-- bigbase36 negative values should convert from ints;
|
||||
SELECT '-2147483647'::bigint::bigbase36;
|
||||
bigbase36
|
||||
-----------
|
||||
-zik0zj
|
||||
(1 row)
|
||||
|
||||
|
||||
18
test/expected/binary_copy_test.out
Normal file
18
test/expected/binary_copy_test.out
Normal file
@@ -0,0 +1,18 @@
|
||||
-- bigbase36 binary should copy data binary from country;
|
||||
BEGIN;
|
||||
CREATE TABLE before (a bigbase36);
|
||||
INSERT INTO before VALUES ('aa'), ('-aa'), ('1y2p0ij32e8e7'), ('-1y2p0ij32e8e7'), ('0');
|
||||
CREATE TABLE after (a bigbase36);
|
||||
COPY before TO '/tmp/tst' WITH (FORMAT binary);
|
||||
COPY after FROM '/tmp/tst' WITH (FORMAT binary);
|
||||
SELECT * FROM after;
|
||||
a
|
||||
----------------
|
||||
aa
|
||||
-aa
|
||||
1y2p0ij32e8e7
|
||||
-1y2p0ij32e8e7
|
||||
0
|
||||
(5 rows)
|
||||
|
||||
ROLLBACK;
|
||||
@@ -1,5 +1,4 @@
|
||||
BEGIN;
|
||||
create extension base36;
|
||||
SET max_parallel_workers_per_gather=4;
|
||||
SET force_parallel_mode=on;
|
||||
CREATE TABLE parallel_test(i int, b1 base36, b2 bigbase36) WITH (parallel_workers = 4);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
BEGIN;
|
||||
create extension base36;
|
||||
SET max_parallel_workers_per_gather=4;
|
||||
SET force_parallel_mode=on;
|
||||
CREATE TABLE parallel_test(i int, b1 base36, b2 bigbase36) WITH (parallel_workers = 4);
|
||||
|
||||
@@ -1,54 +1,22 @@
|
||||
BEGIN;
|
||||
-- base36 conversion should encode integer;
|
||||
-- ./spec/base36_spec.rb:9;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 120::base36;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should decode text;
|
||||
-- ./spec/base36_spec.rb:13;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3c'::base36::int;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should error to big values;
|
||||
-- ./spec/base36_spec.rb:17;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3caaaaaaaaaaaaa'::base36::bigint;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should cast big base36 values;
|
||||
-- ./spec/base36_spec.rb:21;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'zik0zj'::base36::int;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should cast big int values;
|
||||
-- ./spec/base36_spec.rb:25;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 2147483647::base36;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should error to big values;
|
||||
-- ./spec/base36_spec.rb:29;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'zik0zk'::base36::int;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 conversion should error invalid values;
|
||||
-- ./spec/base36_spec.rb:33;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3&'::base36::bigint;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 comparison should compare using >;
|
||||
-- ./spec/base36_spec.rb:39;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'a'::base36 > 'b'::base36;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- base36 comparison should compare using <;
|
||||
-- ./spec/base36_spec.rb:43;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'a'::base36 < 'b'::base36;
|
||||
ROLLBACK;
|
||||
-- base36 negative values should convert from base36;
|
||||
SELECT '-zik0zj'::base36::int;
|
||||
-- base36 negative values should convert from ints;
|
||||
SELECT '-2147483647'::integer::base36;
|
||||
|
||||
@@ -1,54 +1,22 @@
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should encode integer;
|
||||
-- ./spec/bigbase36_spec.rb:9;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 120::bigint::bigbase36;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should decode text;
|
||||
-- ./spec/bigbase36_spec.rb:13;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3c'::bigbase36::bigint;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should error to big values;
|
||||
-- ./spec/bigbase36_spec.rb:17;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3caaaaaaaaaaaaa'::bigbase36::bigint;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should cast big bigbase36 values;
|
||||
-- ./spec/bigbase36_spec.rb:21;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '1y2p0ij32e8e7'::bigbase36::bigint;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should cast big bigint values;
|
||||
-- ./spec/bigbase36_spec.rb:25;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 9223372036854775807::bigbase36;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should error to big values;
|
||||
-- ./spec/bigbase36_spec.rb:29;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '1y2p0ij32e8e8'::bigbase36::bigint;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 conversion should error invalid values;
|
||||
-- ./spec/bigbase36_spec.rb:33;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT '3&'::bigbase36::bigint;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 comparison should compare using >;
|
||||
-- ./spec/bigbase36_spec.rb:39;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'a'::bigbase36 > 'b'::bigbase36;
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
-- bigbase36 comparison should compare using <;
|
||||
-- ./spec/bigbase36_spec.rb:43;
|
||||
CREATE EXTENSION base36;
|
||||
SELECT 'a'::bigbase36 < 'b'::bigbase36;
|
||||
ROLLBACK;
|
||||
-- bigbase36 negative values should convert from base36;
|
||||
SELECT '-zik0zj'::bigbase36::bigint;
|
||||
-- bigbase36 negative values should convert from ints;
|
||||
SELECT '-2147483647'::bigint::bigbase36;
|
||||
|
||||
9
test/sql/binary_copy_test.sql
Normal file
9
test/sql/binary_copy_test.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- bigbase36 binary should copy data binary from country;
|
||||
BEGIN;
|
||||
CREATE TABLE before (a bigbase36);
|
||||
INSERT INTO before VALUES ('aa'), ('-aa'), ('1y2p0ij32e8e7'), ('-1y2p0ij32e8e7'), ('0');
|
||||
CREATE TABLE after (a bigbase36);
|
||||
COPY before TO '/tmp/tst' WITH (FORMAT binary);
|
||||
COPY after FROM '/tmp/tst' WITH (FORMAT binary);
|
||||
SELECT * FROM after;
|
||||
ROLLBACK;
|
||||
@@ -1,5 +1,4 @@
|
||||
BEGIN;
|
||||
create extension base36;
|
||||
SET max_parallel_workers_per_gather=4;
|
||||
SET force_parallel_mode=on;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user