forked from yorickdewid/PostgreSQL-IBAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iban--1.0.0.sql
67 lines (58 loc) · 1.93 KB
/
iban--1.0.0.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- IBAN datatype and verificator -*- sql -*-
---
--- Copyright © 2016-2020 Yorick de Wid <yorick17 at outlook dot com>
---
--- This program is free software: you can redistribute it and/or modify
--- it under the terms of the GNU General Public License as published by
--- the Free Software Foundation, either version 2 of the License, or
--- (at your option) any later version.
---
--- This program is distributed in the hope that it will be useful, but
--- WITHOUT ANY WARRANTY; without even the implied warranty of
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--- General Public License for more details.
---
--- You should have received a copy of the GNU General Public License
--- along with this program. If not, see
--- <http://www.gnu.org/licenses/>.
CREATE TYPE iban;
CREATE OR REPLACE FUNCTION ibanin(cstring)
RETURNS iban
AS 'iban'
LANGUAGE C
IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION ibanout(iban)
RETURNS cstring
AS 'iban'
LANGUAGE C
IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION ibanrecv(internal)
RETURNS iban
AS 'iban'
LANGUAGE C
IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION ibansend(iban)
RETURNS bytea
AS 'iban'
LANGUAGE C
IMMUTABLE STRICT;
CREATE TYPE iban (
LIKE = text,
INPUT = ibanin,
OUTPUT = ibanout,
RECEIVE = ibanrecv,
SEND = ibansend,
-- make it a non-preferred member of string type category
CATEGORY = 'S',
PREFERRED = false
);
COMMENT ON TYPE iban IS 'International Bank Account Number';
CREATE CAST (iban AS text) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (iban AS varchar) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (iban AS bpchar) WITHOUT FUNCTION AS ASSIGNMENT;
CREATE OR REPLACE FUNCTION iban_validate(text)
RETURNS boolean AS 'MODULE_PATHNAME'
LANGUAGE C
IMMUTABLE STRICT;
COMMENT ON FUNCTION iban_validate (text)
IS 'Validate IBAN account';