Created
February 17, 2022 02:36
-
-
Save coderdan/ff10de5b11c520715a7d5c3aafb459fa to your computer and use it in GitHub Desktop.
pg_secret.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TYPE ore_block_64_8; | |
CREATE FUNCTION ore_block_in_64_8(cstring) | |
RETURNS ore_block_64_8 | |
AS '$libdir/pgsecret' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION ore_block_out_64_8(ore_block_64_8) | |
RETURNS cstring | |
AS '$libdir/pgsecret' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION ore_block_send_64_8(ore_block_64_8) | |
RETURNS bytea | |
AS '$libdir/pgsecret' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION ore_block_recv_64_8(internal) | |
RETURNS ore_block_64_8 | |
AS '$libdir/pgsecret' | |
LANGUAGE C IMMUTABLE STRICT; | |
--CREATE TYPE ore_block ( | |
-- input = ore_block_in, | |
-- output = ore_block_out, | |
-- receive = ore_block_recv, | |
-- send = ore_block_send, | |
-- alignment = int | |
--); | |
-- TODO: We may want specific in/out functions here for the different types to validate length | |
CREATE TYPE ore_block_64_8 ( | |
input = ore_block_in_64_8, | |
output = ore_block_out_64_8, | |
receive = ore_block_recv_64_8, | |
send = ore_block_send_64_8, | |
alignment = int | |
); | |
CREATE DOMAIN key AS bytea; | |
-- TODO: size variants needed | |
CREATE FUNCTION make_secret_64_8(key, key, int8) RETURNS ore_block_64_8 | |
AS '$libdir/pgsecret', 'make_secret_64_8' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION make_secret_64_8(key, key, text) RETURNS ore_block_64_8 | |
AS '$libdir/pgsecret', 'make_secret_string_64_8' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION secret_lt(ore_block_64_8, ore_block_64_8) RETURNS bool | |
AS '$libdir/pgsecret', 'secret_lt_64_8' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION secret_eq(ore_block_64_8, ore_block_64_8) RETURNS bool | |
AS '$libdir/pgsecret', 'secret_eq_64_8' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION secret_gt(ore_block_64_8, ore_block_64_8) RETURNS bool | |
AS '$libdir/pgsecret', 'secret_gt_64_8' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION secret_lte(ore_block_64_8, ore_block_64_8) RETURNS bool | |
AS '$libdir/pgsecret', 'secret_lte_64_8' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE FUNCTION secret_gte(ore_block_64_8, ore_block_64_8) RETURNS bool | |
AS '$libdir/pgsecret', 'secret_gte_64_8' | |
LANGUAGE C IMMUTABLE STRICT; | |
CREATE OPERATOR < ( | |
leftarg = ore_block_64_8, | |
rightarg = ore_block_64_8, | |
procedure = secret_lt, | |
commutator = > , | |
negator = >= , | |
restrict = scalarltsel, | |
join = scalarltjoinsel | |
); | |
CREATE OPERATOR = ( | |
leftarg = ore_block_64_8, | |
rightarg = ore_block_64_8, | |
procedure = secret_eq, | |
commutator = = , | |
restrict = eqsel, | |
join = eqjoinsel | |
); | |
CREATE OPERATOR > ( | |
leftarg = ore_block_64_8, | |
rightarg = ore_block_64_8, | |
procedure = secret_gt, | |
commutator = < , | |
negator = <= , | |
restrict = scalargtsel, | |
join = scalargtjoinsel | |
); | |
CREATE OPERATOR <= ( | |
leftarg = ore_block_64_8, | |
rightarg = ore_block_64_8, | |
procedure = secret_lte, | |
commutator = >= , | |
negator = > , | |
restrict = scalarlesel, | |
join = scalarlejoinsel | |
); | |
CREATE OPERATOR >= ( | |
leftarg = ore_block_64_8, | |
rightarg = ore_block_64_8, | |
procedure = secret_gte, | |
commutator = <= , | |
negator = < , | |
restrict = scalargesel, | |
join = scalargejoinsel | |
); | |
CREATE FUNCTION secret_cmp_64_8(ore_block_64_8, ore_block_64_8) RETURNS int4 | |
AS '$libdir/pgsecret' | |
LANGUAGE C IMMUTABLE STRICT; | |
-- now we can make the operator class | |
CREATE OPERATOR CLASS secret_64_8_btree_ops | |
DEFAULT FOR TYPE ore_block_64_8 USING btree AS | |
OPERATOR 1 < , | |
OPERATOR 2 <= , | |
OPERATOR 3 = , | |
OPERATOR 4 >= , | |
OPERATOR 5 > , | |
FUNCTION 1 secret_cmp_64_8(ore_block_64_8, ore_block_64_8); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment