2017-03-13 21:32:50 +00:00
|
|
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
2015-07-16 18:34:42 +00:00
|
|
|
\echo Use "CREATE EXTENSION pg_libphonenumber" to load this file. \quit
|
|
|
|
|
2017-03-13 21:32:50 +00:00
|
|
|
--
|
2019-07-31 06:06:24 +00:00
|
|
|
-- Packed number type
|
2017-03-13 21:32:50 +00:00
|
|
|
--
|
2015-07-16 18:34:42 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE TYPE packed_phone_number;
|
2015-07-23 21:29:13 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_in(cstring) RETURNS packed_phone_number
|
2015-07-16 18:34:42 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_in';
|
2015-07-16 18:34:42 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_out(packed_phone_number) RETURNS cstring
|
2015-07-16 18:34:42 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_out';
|
2015-07-16 18:34:42 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_recv(internal) RETURNS packed_phone_number
|
2015-07-16 18:34:42 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_recv';
|
2015-07-16 18:34:42 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_send(packed_phone_number) RETURNS bytea
|
2015-07-16 18:34:42 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_send';
|
2015-07-16 18:34:42 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE TYPE packed_phone_number (
|
2017-03-13 19:04:26 +00:00
|
|
|
INTERNALLENGTH = 8,
|
2019-07-31 06:06:24 +00:00
|
|
|
INPUT = packed_phone_number_in,
|
|
|
|
OUTPUT = packed_phone_number_out,
|
|
|
|
RECEIVE = packed_phone_number_recv,
|
|
|
|
SEND = packed_phone_number_send,
|
2015-07-16 18:34:42 +00:00
|
|
|
ALIGNMENT = double,
|
|
|
|
STORAGE = plain
|
|
|
|
);
|
|
|
|
|
2017-03-13 21:32:50 +00:00
|
|
|
-- Casts
|
2015-07-23 21:29:13 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE CAST (packed_phone_number AS text)
|
2017-02-18 17:11:41 +00:00
|
|
|
WITH INOUT;
|
2015-07-22 16:57:44 +00:00
|
|
|
|
2017-03-13 21:32:50 +00:00
|
|
|
-- Operators and indexing
|
2015-07-23 21:29:13 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_equal(packed_phone_number, packed_phone_number) RETURNS bool
|
2015-07-23 21:29:13 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_equal';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
|
|
|
CREATE OPERATOR = (
|
2019-07-31 06:06:24 +00:00
|
|
|
leftarg = packed_phone_number,
|
|
|
|
rightarg = packed_phone_number,
|
|
|
|
procedure = packed_phone_number_equal,
|
2017-02-18 17:11:41 +00:00
|
|
|
commutator = =,
|
|
|
|
negator = <>,
|
|
|
|
restrict = eqsel,
|
|
|
|
join = eqjoinsel,
|
|
|
|
hashes = true,
|
|
|
|
merges = true
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_not_equal(packed_phone_number, packed_phone_number) RETURNS bool
|
2015-07-23 21:29:13 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_not_equal';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
|
|
|
CREATE OPERATOR <> (
|
2019-07-31 06:06:24 +00:00
|
|
|
leftarg = packed_phone_number,
|
|
|
|
rightarg = packed_phone_number,
|
|
|
|
procedure = packed_phone_number_not_equal,
|
2017-02-18 17:11:41 +00:00
|
|
|
commutator = <>,
|
|
|
|
negator = =,
|
|
|
|
restrict = neqsel,
|
|
|
|
join = neqjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_less(packed_phone_number, packed_phone_number) RETURNS bool
|
2015-07-23 21:29:13 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_less';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
|
|
|
CREATE OPERATOR < (
|
2019-07-31 06:06:24 +00:00
|
|
|
leftarg = packed_phone_number,
|
|
|
|
rightarg = packed_phone_number,
|
|
|
|
procedure = packed_phone_number_less,
|
2017-02-18 17:11:41 +00:00
|
|
|
commutator = >,
|
|
|
|
negator = >=,
|
|
|
|
restrict = scalarltsel,
|
|
|
|
join = scalarltjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_less_or_equal(packed_phone_number, packed_phone_number) RETURNS bool
|
2015-07-23 21:29:13 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_less_or_equal';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
|
|
|
CREATE OPERATOR <= (
|
2019-07-31 06:06:24 +00:00
|
|
|
leftarg = packed_phone_number,
|
|
|
|
rightarg = packed_phone_number,
|
|
|
|
procedure = packed_phone_number_less_or_equal,
|
2017-02-18 17:11:41 +00:00
|
|
|
commutator = >=,
|
|
|
|
negator = >,
|
|
|
|
restrict = scalarltsel,
|
|
|
|
join = scalarltjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_greater(packed_phone_number, packed_phone_number) RETURNS bool
|
2015-07-23 21:29:13 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_greater';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
|
|
|
CREATE OPERATOR > (
|
2019-07-31 06:06:24 +00:00
|
|
|
leftarg = packed_phone_number,
|
|
|
|
rightarg = packed_phone_number,
|
|
|
|
procedure = packed_phone_number_greater,
|
2017-02-18 17:11:41 +00:00
|
|
|
commutator = >,
|
|
|
|
negator = <=,
|
|
|
|
restrict = scalargtsel,
|
|
|
|
join = scalargtjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_greater_or_equal(packed_phone_number, packed_phone_number) RETURNS bool
|
2015-07-23 21:29:13 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_greater_or_equal';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
|
|
|
CREATE OPERATOR >= (
|
2019-07-31 06:06:24 +00:00
|
|
|
leftarg = packed_phone_number,
|
|
|
|
rightarg = packed_phone_number,
|
|
|
|
procedure = packed_phone_number_greater_or_equal,
|
2017-02-18 17:11:41 +00:00
|
|
|
commutator = >=,
|
|
|
|
negator = <,
|
|
|
|
restrict = scalargtsel,
|
|
|
|
join = scalargtjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION packed_phone_number_cmp(packed_phone_number, packed_phone_number) RETURNS integer
|
2015-07-24 19:48:22 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_cmp';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE OPERATOR CLASS packed_phone_number_ops
|
|
|
|
DEFAULT FOR TYPE packed_phone_number USING btree AS
|
2017-02-18 17:11:41 +00:00
|
|
|
OPERATOR 1 <,
|
|
|
|
OPERATOR 2 <=,
|
|
|
|
OPERATOR 3 =,
|
|
|
|
OPERATOR 4 >=,
|
|
|
|
OPERATOR 5 >,
|
2019-07-31 06:06:24 +00:00
|
|
|
FUNCTION 1 packed_phone_number_cmp(packed_phone_number, packed_phone_number);
|
|
|
|
|
|
|
|
-- Constructors
|
|
|
|
|
|
|
|
CREATE FUNCTION parse_packed_phone_number(text, text) RETURNS packed_phone_number
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'parse_packed_phone_number';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
2017-03-13 21:32:50 +00:00
|
|
|
--
|
|
|
|
-- General functions
|
|
|
|
--
|
2015-07-23 21:29:13 +00:00
|
|
|
|
2019-07-31 06:06:24 +00:00
|
|
|
CREATE FUNCTION phone_number_country_code(packed_phone_number) RETURNS integer
|
2017-03-13 21:32:50 +00:00
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
2019-07-31 06:06:24 +00:00
|
|
|
AS 'pg_libphonenumber', 'packed_phone_number_country_code';
|