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
|
|
|
--
|
|
|
|
-- Phone number type
|
|
|
|
--
|
2015-07-16 18:34:42 +00:00
|
|
|
|
2017-03-13 21:32:50 +00:00
|
|
|
CREATE TYPE phone_number;
|
2015-07-23 21:29:13 +00:00
|
|
|
|
2015-07-16 18:34:42 +00:00
|
|
|
CREATE FUNCTION phone_number_in(cstring) RETURNS phone_number
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_in';
|
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_out(phone_number) RETURNS cstring
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_out';
|
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_recv(internal) RETURNS phone_number
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_recv';
|
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_send(phone_number) RETURNS bytea
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_send';
|
|
|
|
|
|
|
|
CREATE TYPE phone_number (
|
2017-03-13 19:04:26 +00:00
|
|
|
INTERNALLENGTH = 8,
|
2015-07-16 18:34:42 +00:00
|
|
|
INPUT = phone_number_in,
|
|
|
|
OUTPUT = phone_number_out,
|
|
|
|
RECEIVE = phone_number_recv,
|
|
|
|
SEND = phone_number_send,
|
|
|
|
ALIGNMENT = double,
|
|
|
|
STORAGE = plain
|
|
|
|
);
|
|
|
|
|
2017-03-13 21:32:50 +00:00
|
|
|
--
|
|
|
|
-- Casts
|
|
|
|
--
|
2015-07-23 21:29:13 +00:00
|
|
|
|
2015-07-22 16:57:44 +00:00
|
|
|
CREATE CAST (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
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_equal(phone_number, phone_number) RETURNS bool
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_equal';
|
|
|
|
|
|
|
|
CREATE OPERATOR = (
|
2017-02-18 17:11:41 +00:00
|
|
|
leftarg = phone_number,
|
|
|
|
rightarg = phone_number,
|
|
|
|
procedure = phone_number_equal,
|
|
|
|
commutator = =,
|
|
|
|
negator = <>,
|
|
|
|
restrict = eqsel,
|
|
|
|
join = eqjoinsel,
|
|
|
|
hashes = true,
|
|
|
|
merges = true
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_not_equal(phone_number, phone_number) RETURNS bool
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_not_equal';
|
|
|
|
|
|
|
|
CREATE OPERATOR <> (
|
2017-02-18 17:11:41 +00:00
|
|
|
leftarg = phone_number,
|
|
|
|
rightarg = phone_number,
|
|
|
|
procedure = phone_number_not_equal,
|
|
|
|
commutator = <>,
|
|
|
|
negator = =,
|
|
|
|
restrict = neqsel,
|
|
|
|
join = neqjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_less(phone_number, phone_number) RETURNS bool
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_less';
|
|
|
|
|
|
|
|
CREATE OPERATOR < (
|
2017-02-18 17:11:41 +00:00
|
|
|
leftarg = phone_number,
|
|
|
|
rightarg = phone_number,
|
|
|
|
procedure = phone_number_less,
|
|
|
|
commutator = >,
|
|
|
|
negator = >=,
|
|
|
|
restrict = scalarltsel,
|
|
|
|
join = scalarltjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_less_or_equal(phone_number, phone_number) RETURNS bool
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_less_or_equal';
|
|
|
|
|
|
|
|
CREATE OPERATOR <= (
|
2017-02-18 17:11:41 +00:00
|
|
|
leftarg = phone_number,
|
|
|
|
rightarg = phone_number,
|
|
|
|
procedure = phone_number_less_or_equal,
|
|
|
|
commutator = >=,
|
|
|
|
negator = >,
|
|
|
|
restrict = scalarltsel,
|
|
|
|
join = scalarltjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_greater(phone_number, phone_number) RETURNS bool
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_greater';
|
|
|
|
|
|
|
|
CREATE OPERATOR > (
|
2017-02-18 17:11:41 +00:00
|
|
|
leftarg = phone_number,
|
|
|
|
rightarg = phone_number,
|
|
|
|
procedure = phone_number_greater,
|
|
|
|
commutator = >,
|
|
|
|
negator = <=,
|
|
|
|
restrict = scalargtsel,
|
|
|
|
join = scalargtjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION phone_number_greater_or_equal(phone_number, phone_number) RETURNS bool
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_greater_or_equal';
|
|
|
|
|
|
|
|
CREATE OPERATOR >= (
|
2017-02-18 17:11:41 +00:00
|
|
|
leftarg = phone_number,
|
|
|
|
rightarg = phone_number,
|
|
|
|
procedure = phone_number_greater_or_equal,
|
|
|
|
commutator = >=,
|
|
|
|
negator = <,
|
|
|
|
restrict = scalargtsel,
|
|
|
|
join = scalargtjoinsel
|
2015-07-23 21:29:13 +00:00
|
|
|
);
|
|
|
|
|
2015-07-24 19:48:22 +00:00
|
|
|
CREATE FUNCTION phone_number_cmp(phone_number, phone_number) RETURNS integer
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_cmp';
|
2015-07-23 21:29:13 +00:00
|
|
|
|
|
|
|
CREATE OPERATOR CLASS phone_number_ops
|
2017-02-18 17:11:41 +00:00
|
|
|
DEFAULT FOR TYPE phone_number USING btree AS
|
|
|
|
OPERATOR 1 <,
|
|
|
|
OPERATOR 2 <=,
|
|
|
|
OPERATOR 3 =,
|
|
|
|
OPERATOR 4 >=,
|
|
|
|
OPERATOR 5 >,
|
|
|
|
FUNCTION 1 phone_number_cmp(phone_number, 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
|
|
|
|
2015-07-22 16:57:44 +00:00
|
|
|
CREATE FUNCTION parse_phone_number(text, text) RETURNS phone_number
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'parse_phone_number';
|
|
|
|
|
2017-03-13 21:32:50 +00:00
|
|
|
CREATE FUNCTION phone_number_country_code(phone_number) RETURNS integer
|
|
|
|
LANGUAGE c IMMUTABLE STRICT
|
|
|
|
AS 'pg_libphonenumber', 'phone_number_country_code';
|