diff options
Diffstat (limited to 'contrib/isn')
-rw-r--r-- | contrib/isn/.gitignore | 4 | ||||
-rw-r--r-- | contrib/isn/EAN13.h | 148 | ||||
-rw-r--r-- | contrib/isn/ISBN.h | 990 | ||||
-rw-r--r-- | contrib/isn/ISMN.h | 52 | ||||
-rw-r--r-- | contrib/isn/ISSN.h | 49 | ||||
-rw-r--r-- | contrib/isn/Makefile | 24 | ||||
-rw-r--r-- | contrib/isn/UPC.h | 28 | ||||
-rw-r--r-- | contrib/isn/expected/isn.out | 266 | ||||
-rw-r--r-- | contrib/isn/isn--1.0--1.1.sql | 250 | ||||
-rw-r--r-- | contrib/isn/isn--1.1--1.2.sql | 228 | ||||
-rw-r--r-- | contrib/isn/isn--1.1.sql | 3434 | ||||
-rw-r--r-- | contrib/isn/isn.c | 1139 | ||||
-rw-r--r-- | contrib/isn/isn.control | 6 | ||||
-rw-r--r-- | contrib/isn/isn.h | 35 | ||||
-rw-r--r-- | contrib/isn/sql/isn.sql | 113 |
15 files changed, 6766 insertions, 0 deletions
diff --git a/contrib/isn/.gitignore b/contrib/isn/.gitignore new file mode 100644 index 0000000..5dcb3ff --- /dev/null +++ b/contrib/isn/.gitignore @@ -0,0 +1,4 @@ +# Generated subdirectories +/log/ +/results/ +/tmp_check/ diff --git a/contrib/isn/EAN13.h b/contrib/isn/EAN13.h new file mode 100644 index 0000000..7023ebd --- /dev/null +++ b/contrib/isn/EAN13.h @@ -0,0 +1,148 @@ +/* + * EAN13.h + * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) + * + * Information recompiled by Kronuz on August 23, 2006 + * http://www.gs1.org/productssolutions/idkeys/support/prefix_list.html + * + * IDENTIFICATION + * contrib/isn/EAN13.h + * + */ + +/* where the digit set begins, and how many of them are in the table */ +const unsigned EAN13_index[10][2] = { + {0, 6}, + {6, 1}, + {7, 1}, + {8, 5}, + {13, 20}, + {33, 15}, + {48, 19}, + {67, 23}, + {90, 17}, + {107, 12}, +}; +const char *EAN13_range[][2] = { + {"000", "019"}, /* GS1 US */ + {"020", "029"}, /* Restricted distribution (MO defined) */ + {"030", "039"}, /* GS1 US */ + {"040", "049"}, /* Restricted distribution (MO defined) */ + {"050", "059"}, /* Coupons */ + {"060", "099"}, /* GS1 US */ + {"100", "139"}, /* GS1 US */ + {"200", "299"}, /* Restricted distribution (MO defined) */ + {"300", "379"}, /* GS1 France */ + {"380", "380"}, /* GS1 Bulgaria */ + {"383", "383"}, /* GS1 Slovenija */ + {"385", "385"}, /* GS1 Croatia */ + {"387", "387"}, /* GS1 BIH (Bosnia-Herzegovina) */ + {"400", "440"}, /* GS1 Germany */ + {"450", "459"}, /* GS1 Japan */ + {"460", "469"}, /* GS1 Russia */ + {"470", "470"}, /* GS1 Kyrgyzstan */ + {"471", "471"}, /* GS1 Taiwan */ + {"474", "474"}, /* GS1 Estonia */ + {"475", "475"}, /* GS1 Latvia */ + {"476", "476"}, /* GS1 Azerbaijan */ + {"477", "477"}, /* GS1 Lithuania */ + {"478", "478"}, /* GS1 Uzbekistan */ + {"479", "479"}, /* GS1 Sri Lanka */ + {"480", "480"}, /* GS1 Philippines */ + {"481", "481"}, /* GS1 Belarus */ + {"482", "482"}, /* GS1 Ukraine */ + {"484", "484"}, /* GS1 Moldova */ + {"485", "485"}, /* GS1 Armenia */ + {"486", "486"}, /* GS1 Georgia */ + {"487", "487"}, /* GS1 Kazakstan */ + {"489", "489"}, /* GS1 Hong Kong */ + {"490", "499"}, /* GS1 Japan */ + {"500", "509"}, /* GS1 UK */ + {"520", "520"}, /* GS1 Greece */ + {"528", "528"}, /* GS1 Lebanon */ + {"529", "529"}, /* GS1 Cyprus */ + {"530", "530"}, /* GS1 Albania */ + {"531", "531"}, /* GS1 MAC (FYR Macedonia) */ + {"535", "535"}, /* GS1 Malta */ + {"539", "539"}, /* GS1 Ireland */ + {"540", "549"}, /* GS1 Belgium & Luxembourg */ + {"560", "560"}, /* GS1 Portugal */ + {"569", "569"}, /* GS1 Iceland */ + {"570", "579"}, /* GS1 Denmark */ + {"590", "590"}, /* GS1 Poland */ + {"594", "594"}, /* GS1 Romania */ + {"599", "599"}, /* GS1 Hungary */ + {"600", "601"}, /* GS1 South Africa */ + {"603", "603"}, /* GS1 Ghana */ + {"608", "608"}, /* GS1 Bahrain */ + {"609", "609"}, /* GS1 Mauritius */ + {"611", "611"}, /* GS1 Morocco */ + {"613", "613"}, /* GS1 Algeria */ + {"616", "616"}, /* GS1 Kenya */ + {"618", "618"}, /* GS1 Ivory Coast */ + {"619", "619"}, /* GS1 Tunisia */ + {"621", "621"}, /* GS1 Syria */ + {"622", "622"}, /* GS1 Egypt */ + {"624", "624"}, /* GS1 Libya */ + {"625", "625"}, /* GS1 Jordan */ + {"626", "626"}, /* GS1 Iran */ + {"627", "627"}, /* GS1 Kuwait */ + {"628", "628"}, /* GS1 Saudi Arabia */ + {"629", "629"}, /* GS1 Emirates */ + {"640", "649"}, /* GS1 Finland */ + {"690", "695"}, /* GS1 China */ + {"700", "709"}, /* GS1 Norway */ + {"729", "729"}, /* GS1 Israel */ + {"730", "739"}, /* GS1 Sweden */ + {"740", "740"}, /* GS1 Guatemala */ + {"741", "741"}, /* GS1 El Salvador */ + {"742", "742"}, /* GS1 Honduras */ + {"743", "743"}, /* GS1 Nicaragua */ + {"744", "744"}, /* GS1 Costa Rica */ + {"745", "745"}, /* GS1 Panama */ + {"746", "746"}, /* GS1 Republica Dominicana */ + {"750", "750"}, /* GS1 Mexico */ + {"754", "755"}, /* GS1 Canada */ + {"759", "759"}, /* GS1 Venezuela */ + {"760", "769"}, /* GS1 Schweiz, Suisse, Svizzera */ + {"770", "770"}, /* GS1 Colombia */ + {"773", "773"}, /* GS1 Uruguay */ + {"775", "775"}, /* GS1 Peru */ + {"777", "777"}, /* GS1 Bolivia */ + {"779", "779"}, /* GS1 Argentina */ + {"780", "780"}, /* GS1 Chile */ + {"784", "784"}, /* GS1 Paraguay */ + {"786", "786"}, /* GS1 Ecuador */ + {"789", "790"}, /* GS1 Brasil */ + {"800", "839"}, /* GS1 Italy */ + {"840", "849"}, /* GS1 Spain */ + {"850", "850"}, /* GS1 Cuba */ + {"858", "858"}, /* GS1 Slovakia */ + {"859", "859"}, /* GS1 Czech */ + {"860", "860"}, /* GS1 YU (Serbia & Montenegro) */ + {"865", "865"}, /* GS1 Mongolia */ + {"867", "867"}, /* GS1 North Korea */ + {"869", "869"}, /* GS1 Turkey */ + {"870", "879"}, /* GS1 Netherlands */ + {"880", "880"}, /* GS1 South Korea */ + {"884", "884"}, /* GS1 Cambodia */ + {"885", "885"}, /* GS1 Thailand */ + {"888", "888"}, /* GS1 Singapore */ + {"890", "890"}, /* GS1 India */ + {"893", "893"}, /* GS1 Vietnam */ + {"899", "899"}, /* GS1 Indonesia */ + {"900", "919"}, /* GS1 Austria */ + {"930", "939"}, /* GS1 Australia */ + {"940", "949"}, /* GS1 New Zealand */ + {"950", "950"}, /* GS1 Head Office */ + {"955", "955"}, /* GS1 Malaysia */ + {"958", "958"}, /* GS1 Macau */ + {"977", "977"}, /* Serial publications (ISSN) */ + {"978", "978"}, /* Bookland (ISBN) */ + {"979", "979"}, /* International Standard Music Number (ISMN) + * and ISBN contingent */ + {"980", "980"}, /* Refund receipts */ + {"981", "982"}, /* Common Currency Coupons */ + {"990", "999"}, /* Coupons */ + {NULL, NULL} +}; diff --git a/contrib/isn/ISBN.h b/contrib/isn/ISBN.h new file mode 100644 index 0000000..dbda6fb --- /dev/null +++ b/contrib/isn/ISBN.h @@ -0,0 +1,990 @@ +/* + * ISBN.h + * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) + * + * Information recompiled by Kronuz on June 20, 2006 + * http://www.isbn-international.org/ + * http://www.isbn.org/ + * + * IDENTIFICATION + * contrib/isn/ISBN.h + * + * 0-393-04002-X => 039304002(X) <=> 039304002 <=> (978)039304002 <=> 978039304002(9) <=> 978-0-393-04002-9 + * + * + * ISBN 0 3 9 3 0 4 0 0 2 + * Weight 10 9 8 7 6 5 4 3 2 + * Product 0 + 27 + 72 + 21 + 0 + 20 + 0 + 0 + 4 = 144 + * 144 / 11 = 13 remainder 1 + * Check digit 11 - 1 = 10 = X + * => 0-393-04002-X + * + * ISBN 9 7 8 0 3 9 3 0 4 0 0 2 + * Weight 1 3 1 3 1 3 1 3 1 3 1 3 + * Product 9 + 21 + 8 + 0 + 3 + 27 + 3 + 0 + 4 + 0 + 0 + 6 = 81 + * 81 / 10 = 8 remainder 1 + * Check digit 10 - 1 = 9 + * => 978-0-393-04002-9 + * + */ + +/* + * For ISBN with prefix 978 + * Range Table as of 2010-Jul-29 + */ + +/* where the digit set begins, and how many of them are in the table */ +const unsigned ISBN_index[10][2] = { + {0, 6}, + {6, 6}, + {12, 8}, + {20, 14}, + {34, 6}, + {40, 19}, + {59, 68}, + {127, 5}, + {132, 60}, + {192, 718}, +}; + +const char *ISBN_range[][2] = { + {"0-00", "0-19"}, + {"0-200", "0-699"}, + {"0-7000", "0-8499"}, + {"0-85000", "0-89999"}, + {"0-900000", "0-949999"}, + {"0-9500000", "0-9999999"}, + {"1-00", "1-09"}, + {"1-100", "1-399"}, + {"1-4000", "1-5499"}, + {"1-55000", "1-86979"}, + {"1-869800", "1-998999"}, + {"1-9990000", "1-9999999"}, + {"2-00", "2-19"}, + {"2-200", "2-349"}, + {"2-35000", "2-39999"}, + {"2-400", "2-699"}, + {"2-7000", "2-8399"}, + {"2-84000", "2-89999"}, + {"2-900000", "2-949999"}, + {"2-9500000", "2-9999999"}, + {"3-00", "3-02"}, + {"3-030", "3-033"}, + {"3-0340", "3-0369"}, + {"3-03700", "3-03999"}, + {"3-04", "3-19"}, + {"3-200", "3-699"}, + {"3-7000", "3-8499"}, + {"3-85000", "3-89999"}, + {"3-900000", "3-949999"}, + {"3-9500000", "3-9539999"}, + {"3-95400", "3-96999"}, + {"3-9700000", "3-9899999"}, + {"3-99000", "3-99499"}, + {"3-99500", "3-99999"}, + {"4-00", "4-19"}, + {"4-200", "4-699"}, + {"4-7000", "4-8499"}, + {"4-85000", "4-89999"}, + {"4-900000", "4-949999"}, + {"4-9500000", "4-9999999"}, + {"5-00", "5-19"}, + {"5-200", "5-420"}, + {"5-4210", "5-4299"}, + {"5-430", "5-430"}, + {"5-4310", "5-4399"}, + {"5-440", "5-440"}, + {"5-4410", "5-4499"}, + {"5-450", "5-699"}, + {"5-7000", "5-8499"}, + {"5-85000", "5-89999"}, + {"5-900000", "5-909999"}, + {"5-91000", "5-91999"}, + {"5-9200", "5-9299"}, + {"5-93000", "5-94999"}, + {"5-9500000", "5-9500999"}, + {"5-9501", "5-9799"}, + {"5-98000", "5-98999"}, + {"5-9900000", "5-9909999"}, + {"5-9910", "5-9999"}, + {"600-00", "600-09"}, + {"600-100", "600-499"}, + {"600-5000", "600-8999"}, + {"600-90000", "600-99999"}, + {"601-00", "601-19"}, + {"601-200", "601-699"}, + {"601-7000", "601-7999"}, + {"601-80000", "601-84999"}, + {"601-85", "601-99"}, + {"602-00", "602-19"}, + {"602-200", "602-799"}, + {"602-8000", "602-9499"}, + {"602-95000", "602-99999"}, + {"603-00", "603-04"}, + {"603-05", "603-49"}, + {"603-500", "603-799"}, + {"603-8000", "603-8999"}, + {"603-90000", "603-99999"}, + {"604-0", "604-4"}, + {"604-50", "604-89"}, + {"604-900", "604-979"}, + {"604-9800", "604-9999"}, + {"605-01", "605-09"}, + {"605-100", "605-399"}, + {"605-4000", "605-5999"}, + {"605-60000", "605-89999"}, + {"605-90", "605-99"}, + {"606-0", "606-0"}, + {"606-10", "606-49"}, + {"606-500", "606-799"}, + {"606-8000", "606-9199"}, + {"606-92000", "606-99999"}, + {"607-00", "607-39"}, + {"607-400", "607-749"}, + {"607-7500", "607-9499"}, + {"607-95000", "607-99999"}, + {"608-0", "608-0"}, + {"608-10", "608-19"}, + {"608-200", "608-449"}, + {"608-4500", "608-6499"}, + {"608-65000", "608-69999"}, + {"608-7", "608-9"}, + {"609-00", "609-39"}, + {"609-400", "609-799"}, + {"609-8000", "609-9499"}, + {"609-95000", "609-99999"}, + {"612-00", "612-29"}, + {"612-300", "612-399"}, + {"612-4000", "612-4499"}, + {"612-45000", "612-49999"}, + {"612-50", "612-99"}, + {"613-0", "613-9"}, + {"614-00", "614-39"}, + {"614-400", "614-799"}, + {"614-8000", "614-9499"}, + {"614-95000", "614-99999"}, + {"615-00", "615-09"}, + {"615-100", "615-499"}, + {"615-5000", "615-7999"}, + {"615-80000", "615-89999"}, + {"616-00", "616-19"}, + {"616-200", "616-699"}, + {"616-7000", "616-8999"}, + {"616-90000", "616-99999"}, + {"617-00", "617-49"}, + {"617-500", "617-699"}, + {"617-7000", "617-8999"}, + {"617-90000", "617-99999"}, + {"7-00", "7-09"}, + {"7-100", "7-499"}, + {"7-5000", "7-7999"}, + {"7-80000", "7-89999"}, + {"7-900000", "7-999999"}, + {"80-00", "80-19"}, + {"80-200", "80-699"}, + {"80-7000", "80-8499"}, + {"80-85000", "80-89999"}, + {"80-900000", "80-999999"}, + {"81-00", "81-19"}, + {"81-200", "81-699"}, + {"81-7000", "81-8499"}, + {"81-85000", "81-89999"}, + {"81-900000", "81-999999"}, + {"82-00", "82-19"}, + {"82-200", "82-699"}, + {"82-7000", "82-8999"}, + {"82-90000", "82-98999"}, + {"82-990000", "82-999999"}, + {"83-00", "83-19"}, + {"83-200", "83-599"}, + {"83-60000", "83-69999"}, + {"83-7000", "83-8499"}, + {"83-85000", "83-89999"}, + {"83-900000", "83-999999"}, + {"84-00", "84-14"}, + {"84-15000", "84-19999"}, + {"84-200", "84-699"}, + {"84-7000", "84-8499"}, + {"84-85000", "84-89999"}, + {"84-9000", "84-9199"}, + {"84-920000", "84-923999"}, + {"84-92400", "84-92999"}, + {"84-930000", "84-949999"}, + {"84-95000", "84-96999"}, + {"84-9700", "84-9999"}, + {"85-00", "85-19"}, + {"85-200", "85-599"}, + {"85-60000", "85-69999"}, + {"85-7000", "85-8499"}, + {"85-85000", "85-89999"}, + {"85-900000", "85-979999"}, + {"85-98000", "85-99999"}, + {"86-00", "86-29"}, + {"86-300", "86-599"}, + {"86-6000", "86-7999"}, + {"86-80000", "86-89999"}, + {"86-900000", "86-999999"}, + {"87-00", "87-29"}, + {"87-400", "87-649"}, + {"87-7000", "87-7999"}, + {"87-85000", "87-94999"}, + {"87-970000", "87-999999"}, + {"88-00", "88-19"}, + {"88-200", "88-599"}, + {"88-6000", "88-8499"}, + {"88-85000", "88-89999"}, + {"88-900000", "88-949999"}, + {"88-95000", "88-99999"}, + {"89-00", "89-24"}, + {"89-250", "89-549"}, + {"89-5500", "89-8499"}, + {"89-85000", "89-94999"}, + {"89-950000", "89-999999"}, + {"90-00", "90-19"}, + {"90-200", "90-499"}, + {"90-5000", "90-6999"}, + {"90-70000", "90-79999"}, + {"90-800000", "90-849999"}, + {"90-8500", "90-8999"}, + {"90-90", "90-90"}, + {"90-910000", "90-939999"}, + {"90-94", "90-94"}, + {"90-950000", "90-999999"}, + {"91-0", "91-1"}, + {"91-20", "91-49"}, + {"91-500", "91-649"}, + {"91-7000", "91-7999"}, + {"91-85000", "91-94999"}, + {"91-970000", "91-999999"}, + {"92-0", "92-5"}, + {"92-60", "92-79"}, + {"92-800", "92-899"}, + {"92-9000", "92-9499"}, + {"92-95000", "92-98999"}, + {"92-990000", "92-999999"}, + {"93-00", "93-09"}, + {"93-100", "93-499"}, + {"93-5000", "93-7999"}, + {"93-80000", "93-94999"}, + {"93-950000", "93-999999"}, + {"94-000", "94-599"}, + {"94-6000", "94-8999"}, + {"94-90000", "94-99999"}, + {"950-00", "950-49"}, + {"950-500", "950-899"}, + {"950-9000", "950-9899"}, + {"950-99000", "950-99999"}, + {"951-0", "951-1"}, + {"951-20", "951-54"}, + {"951-550", "951-889"}, + {"951-8900", "951-9499"}, + {"951-95000", "951-99999"}, + {"952-00", "952-19"}, + {"952-200", "952-499"}, + {"952-5000", "952-5999"}, + {"952-60", "952-65"}, + {"952-6600", "952-6699"}, + {"952-67000", "952-69999"}, + {"952-7000", "952-7999"}, + {"952-80", "952-94"}, + {"952-9500", "952-9899"}, + {"952-99000", "952-99999"}, + {"953-0", "953-0"}, + {"953-10", "953-14"}, + {"953-150", "953-549"}, + {"953-55000", "953-59999"}, + {"953-6000", "953-9499"}, + {"953-95000", "953-99999"}, + {"954-00", "954-28"}, + {"954-2900", "954-2999"}, + {"954-300", "954-799"}, + {"954-8000", "954-8999"}, + {"954-90000", "954-92999"}, + {"954-9300", "954-9999"}, + {"955-0000", "955-1999"}, + {"955-20", "955-49"}, + {"955-50000", "955-54999"}, + {"955-550", "955-799"}, + {"955-8000", "955-9499"}, + {"955-95000", "955-99999"}, + {"956-00", "956-19"}, + {"956-200", "956-699"}, + {"956-7000", "956-9999"}, + {"957-00", "957-02"}, + {"957-0300", "957-0499"}, + {"957-05", "957-19"}, + {"957-2000", "957-2099"}, + {"957-21", "957-27"}, + {"957-28000", "957-30999"}, + {"957-31", "957-43"}, + {"957-440", "957-819"}, + {"957-8200", "957-9699"}, + {"957-97000", "957-99999"}, + {"958-00", "958-56"}, + {"958-57000", "958-59999"}, + {"958-600", "958-799"}, + {"958-8000", "958-9499"}, + {"958-95000", "958-99999"}, + {"959-00", "959-19"}, + {"959-200", "959-699"}, + {"959-7000", "959-8499"}, + {"959-85000", "959-99999"}, + {"960-00", "960-19"}, + {"960-200", "960-659"}, + {"960-6600", "960-6899"}, + {"960-690", "960-699"}, + {"960-7000", "960-8499"}, + {"960-85000", "960-92999"}, + {"960-93", "960-93"}, + {"960-9400", "960-9799"}, + {"960-98000", "960-99999"}, + {"961-00", "961-19"}, + {"961-200", "961-599"}, + {"961-6000", "961-8999"}, + {"961-90000", "961-94999"}, + {"962-00", "962-19"}, + {"962-200", "962-699"}, + {"962-7000", "962-8499"}, + {"962-85000", "962-86999"}, + {"962-8700", "962-8999"}, + {"962-900", "962-999"}, + {"963-00", "963-19"}, + {"963-200", "963-699"}, + {"963-7000", "963-8499"}, + {"963-85000", "963-89999"}, + {"963-9000", "963-9999"}, + {"964-00", "964-14"}, + {"964-150", "964-249"}, + {"964-2500", "964-2999"}, + {"964-300", "964-549"}, + {"964-5500", "964-8999"}, + {"964-90000", "964-96999"}, + {"964-970", "964-989"}, + {"964-9900", "964-9999"}, + {"965-00", "965-19"}, + {"965-200", "965-599"}, + {"965-7000", "965-7999"}, + {"965-90000", "965-99999"}, + {"966-00", "966-14"}, + {"966-1500", "966-1699"}, + {"966-170", "966-199"}, + {"966-2000", "966-2999"}, + {"966-300", "966-699"}, + {"966-7000", "966-8999"}, + {"966-90000", "966-99999"}, + {"967-00", "967-29"}, + {"967-300", "967-499"}, + {"967-5000", "967-5999"}, + {"967-60", "967-89"}, + {"967-900", "967-989"}, + {"967-9900", "967-9989"}, + {"967-99900", "967-99999"}, + {"968-01", "968-39"}, + {"968-400", "968-499"}, + {"968-5000", "968-7999"}, + {"968-800", "968-899"}, + {"968-9000", "968-9999"}, + {"969-0", "969-1"}, + {"969-20", "969-39"}, + {"969-400", "969-799"}, + {"969-8000", "969-9999"}, + {"970-01", "970-59"}, + {"970-600", "970-899"}, + {"970-9000", "970-9099"}, + {"970-91000", "970-96999"}, + {"970-9700", "970-9999"}, + {"971-000", "971-015"}, + {"971-0160", "971-0199"}, + {"971-02", "971-02"}, + {"971-0300", "971-0599"}, + {"971-06", "971-09"}, + {"971-10", "971-49"}, + {"971-500", "971-849"}, + {"971-8500", "971-9099"}, + {"971-91000", "971-98999"}, + {"971-9900", "971-9999"}, + {"972-0", "972-1"}, + {"972-20", "972-54"}, + {"972-550", "972-799"}, + {"972-8000", "972-9499"}, + {"972-95000", "972-99999"}, + {"973-0", "973-0"}, + {"973-100", "973-169"}, + {"973-1700", "973-1999"}, + {"973-20", "973-54"}, + {"973-550", "973-759"}, + {"973-7600", "973-8499"}, + {"973-85000", "973-88999"}, + {"973-8900", "973-9499"}, + {"973-95000", "973-99999"}, + {"974-00", "974-19"}, + {"974-200", "974-699"}, + {"974-7000", "974-8499"}, + {"974-85000", "974-89999"}, + {"974-90000", "974-94999"}, + {"974-9500", "974-9999"}, + {"975-00000", "975-00999"}, + {"975-01", "975-01"}, + {"975-02", "975-24"}, + {"975-250", "975-599"}, + {"975-6000", "975-9199"}, + {"975-92000", "975-98999"}, + {"975-990", "975-999"}, + {"976-0", "976-3"}, + {"976-40", "976-59"}, + {"976-600", "976-799"}, + {"976-8000", "976-9499"}, + {"976-95000", "976-99999"}, + {"977-00", "977-19"}, + {"977-200", "977-499"}, + {"977-5000", "977-6999"}, + {"977-700", "977-999"}, + {"978-000", "978-199"}, + {"978-2000", "978-2999"}, + {"978-30000", "978-79999"}, + {"978-8000", "978-8999"}, + {"978-900", "978-999"}, + {"979-000", "979-099"}, + {"979-1000", "979-1499"}, + {"979-15000", "979-19999"}, + {"979-20", "979-29"}, + {"979-3000", "979-3999"}, + {"979-400", "979-799"}, + {"979-8000", "979-9499"}, + {"979-95000", "979-99999"}, + {"980-00", "980-19"}, + {"980-200", "980-599"}, + {"980-6000", "980-9999"}, + {"981-00", "981-11"}, + {"981-1200", "981-1999"}, + {"981-200", "981-289"}, + {"981-2900", "981-9999"}, + {"982-00", "982-09"}, + {"982-100", "982-699"}, + {"982-70", "982-89"}, + {"982-9000", "982-9799"}, + {"982-98000", "982-99999"}, + {"983-00", "983-01"}, + {"983-020", "983-199"}, + {"983-2000", "983-3999"}, + {"983-40000", "983-44999"}, + {"983-45", "983-49"}, + {"983-50", "983-79"}, + {"983-800", "983-899"}, + {"983-9000", "983-9899"}, + {"983-99000", "983-99999"}, + {"984-00", "984-39"}, + {"984-400", "984-799"}, + {"984-8000", "984-8999"}, + {"984-90000", "984-99999"}, + {"985-00", "985-39"}, + {"985-400", "985-599"}, + {"985-6000", "985-8999"}, + {"985-90000", "985-99999"}, + {"986-00", "986-11"}, + {"986-120", "986-559"}, + {"986-5600", "986-7999"}, + {"986-80000", "986-99999"}, + {"987-00", "987-09"}, + {"987-1000", "987-1999"}, + {"987-20000", "987-29999"}, + {"987-30", "987-49"}, + {"987-500", "987-899"}, + {"987-9000", "987-9499"}, + {"987-95000", "987-99999"}, + {"988-00", "988-16"}, + {"988-17000", "988-19999"}, + {"988-200", "988-799"}, + {"988-8000", "988-9699"}, + {"988-97000", "988-99999"}, + {"989-0", "989-1"}, + {"989-20", "989-54"}, + {"989-550", "989-799"}, + {"989-8000", "989-9499"}, + {"989-95000", "989-99999"}, + {"9927-00", "9927-09"}, + {"9927-100", "9927-399"}, + {"9927-4000", "9927-4999"}, + {"9928-00", "9928-09"}, + {"9928-100", "9928-399"}, + {"9928-4000", "9928-4999"}, + {"9929-0", "9929-3"}, + {"9929-40", "9929-54"}, + {"9929-550", "9929-799"}, + {"9929-8000", "9929-9999"}, + {"9930-00", "9930-49"}, + {"9930-500", "9930-939"}, + {"9930-9400", "9930-9999"}, + {"9931-00", "9931-29"}, + {"9931-300", "9931-899"}, + {"9931-9000", "9931-9999"}, + {"9932-00", "9932-39"}, + {"9932-400", "9932-849"}, + {"9932-8500", "9932-9999"}, + {"9933-0", "9933-0"}, + {"9933-10", "9933-39"}, + {"9933-400", "9933-899"}, + {"9933-9000", "9933-9999"}, + {"9934-0", "9934-0"}, + {"9934-10", "9934-49"}, + {"9934-500", "9934-799"}, + {"9934-8000", "9934-9999"}, + {"9935-0", "9935-0"}, + {"9935-10", "9935-39"}, + {"9935-400", "9935-899"}, + {"9935-9000", "9935-9999"}, + {"9936-0", "9936-1"}, + {"9936-20", "9936-39"}, + {"9936-400", "9936-799"}, + {"9936-8000", "9936-9999"}, + {"9937-0", "9937-2"}, + {"9937-30", "9937-49"}, + {"9937-500", "9937-799"}, + {"9937-8000", "9937-9999"}, + {"9938-00", "9938-79"}, + {"9938-800", "9938-949"}, + {"9938-9500", "9938-9999"}, + {"9939-0", "9939-4"}, + {"9939-50", "9939-79"}, + {"9939-800", "9939-899"}, + {"9939-9000", "9939-9999"}, + {"9940-0", "9940-1"}, + {"9940-20", "9940-49"}, + {"9940-500", "9940-899"}, + {"9940-9000", "9940-9999"}, + {"9941-0", "9941-0"}, + {"9941-10", "9941-39"}, + {"9941-400", "9941-899"}, + {"9941-9000", "9941-9999"}, + {"9942-00", "9942-89"}, + {"9942-900", "9942-994"}, + {"9942-9950", "9942-9999"}, + {"9943-00", "9943-29"}, + {"9943-300", "9943-399"}, + {"9943-4000", "9943-9999"}, + {"9944-0000", "9944-0999"}, + {"9944-100", "9944-499"}, + {"9944-5000", "9944-5999"}, + {"9944-60", "9944-69"}, + {"9944-700", "9944-799"}, + {"9944-80", "9944-89"}, + {"9944-900", "9944-999"}, + {"9945-00", "9945-00"}, + {"9945-010", "9945-079"}, + {"9945-08", "9945-39"}, + {"9945-400", "9945-569"}, + {"9945-57", "9945-57"}, + {"9945-580", "9945-849"}, + {"9945-8500", "9945-9999"}, + {"9946-0", "9946-1"}, + {"9946-20", "9946-39"}, + {"9946-400", "9946-899"}, + {"9946-9000", "9946-9999"}, + {"9947-0", "9947-1"}, + {"9947-20", "9947-79"}, + {"9947-800", "9947-999"}, + {"9948-00", "9948-39"}, + {"9948-400", "9948-849"}, + {"9948-8500", "9948-9999"}, + {"9949-0", "9949-0"}, + {"9949-10", "9949-39"}, + {"9949-400", "9949-899"}, + {"9949-9000", "9949-9999"}, + {"9950-00", "9950-29"}, + {"9950-300", "9950-849"}, + {"9950-8500", "9950-9999"}, + {"9951-00", "9951-39"}, + {"9951-400", "9951-849"}, + {"9951-8500", "9951-9999"}, + {"9952-0", "9952-1"}, + {"9952-20", "9952-39"}, + {"9952-400", "9952-799"}, + {"9952-8000", "9952-9999"}, + {"9953-0", "9953-0"}, + {"9953-10", "9953-39"}, + {"9953-400", "9953-599"}, + {"9953-60", "9953-89"}, + {"9953-9000", "9953-9999"}, + {"9954-0", "9954-1"}, + {"9954-20", "9954-39"}, + {"9954-400", "9954-799"}, + {"9954-8000", "9954-9999"}, + {"9955-00", "9955-39"}, + {"9955-400", "9955-929"}, + {"9955-9300", "9955-9999"}, + {"9956-0", "9956-0"}, + {"9956-10", "9956-39"}, + {"9956-400", "9956-899"}, + {"9956-9000", "9956-9999"}, + {"9957-00", "9957-39"}, + {"9957-400", "9957-699"}, + {"9957-70", "9957-84"}, + {"9957-8500", "9957-8799"}, + {"9957-88", "9957-99"}, + {"9958-0", "9958-0"}, + {"9958-10", "9958-49"}, + {"9958-500", "9958-899"}, + {"9958-9000", "9958-9999"}, + {"9959-0", "9959-1"}, + {"9959-20", "9959-79"}, + {"9959-800", "9959-949"}, + {"9959-9500", "9959-9999"}, + {"9960-00", "9960-59"}, + {"9960-600", "9960-899"}, + {"9960-9000", "9960-9999"}, + {"9961-0", "9961-2"}, + {"9961-30", "9961-69"}, + {"9961-700", "9961-949"}, + {"9961-9500", "9961-9999"}, + {"9962-00", "9962-54"}, + {"9962-5500", "9962-5599"}, + {"9962-56", "9962-59"}, + {"9962-600", "9962-849"}, + {"9962-8500", "9962-9999"}, + {"9963-0", "9963-2"}, + {"9963-30", "9963-54"}, + {"9963-550", "9963-734"}, + {"9963-7350", "9963-7499"}, + {"9963-7500", "9963-9999"}, + {"9964-0", "9964-6"}, + {"9964-70", "9964-94"}, + {"9964-950", "9964-999"}, + {"9965-00", "9965-39"}, + {"9965-400", "9965-899"}, + {"9965-9000", "9965-9999"}, + {"9966-000", "9966-199"}, + {"9966-20", "9966-69"}, + {"9966-7000", "9966-7499"}, + {"9966-750", "9966-959"}, + {"9966-9600", "9966-9999"}, + {"9967-00", "9967-39"}, + {"9967-400", "9967-899"}, + {"9967-9000", "9967-9999"}, + {"9968-00", "9968-49"}, + {"9968-500", "9968-939"}, + {"9968-9400", "9968-9999"}, + {"9970-00", "9970-39"}, + {"9970-400", "9970-899"}, + {"9970-9000", "9970-9999"}, + {"9971-0", "9971-5"}, + {"9971-60", "9971-89"}, + {"9971-900", "9971-989"}, + {"9971-9900", "9971-9999"}, + {"9972-00", "9972-09"}, + {"9972-1", "9972-1"}, + {"9972-200", "9972-249"}, + {"9972-2500", "9972-2999"}, + {"9972-30", "9972-59"}, + {"9972-600", "9972-899"}, + {"9972-9000", "9972-9999"}, + {"9973-00", "9973-05"}, + {"9973-060", "9973-089"}, + {"9973-0900", "9973-0999"}, + {"9973-10", "9973-69"}, + {"9973-700", "9973-969"}, + {"9973-9700", "9973-9999"}, + {"9974-0", "9974-2"}, + {"9974-30", "9974-54"}, + {"9974-550", "9974-749"}, + {"9974-7500", "9974-9499"}, + {"9974-95", "9974-99"}, + {"9975-0", "9975-0"}, + {"9975-100", "9975-399"}, + {"9975-4000", "9975-4499"}, + {"9975-45", "9975-89"}, + {"9975-900", "9975-949"}, + {"9975-9500", "9975-9999"}, + {"9976-0", "9976-5"}, + {"9976-60", "9976-89"}, + {"9976-900", "9976-989"}, + {"9976-9900", "9976-9999"}, + {"9977-00", "9977-89"}, + {"9977-900", "9977-989"}, + {"9977-9900", "9977-9999"}, + {"9978-00", "9978-29"}, + {"9978-300", "9978-399"}, + {"9978-40", "9978-94"}, + {"9978-950", "9978-989"}, + {"9978-9900", "9978-9999"}, + {"9979-0", "9979-4"}, + {"9979-50", "9979-64"}, + {"9979-650", "9979-659"}, + {"9979-66", "9979-75"}, + {"9979-760", "9979-899"}, + {"9979-9000", "9979-9999"}, + {"9980-0", "9980-3"}, + {"9980-40", "9980-89"}, + {"9980-900", "9980-989"}, + {"9980-9900", "9980-9999"}, + {"9981-00", "9981-09"}, + {"9981-100", "9981-159"}, + {"9981-1600", "9981-1999"}, + {"9981-20", "9981-79"}, + {"9981-800", "9981-949"}, + {"9981-9500", "9981-9999"}, + {"9982-00", "9982-79"}, + {"9982-800", "9982-989"}, + {"9982-9900", "9982-9999"}, + {"9983-80", "9983-94"}, + {"9983-950", "9983-989"}, + {"9983-9900", "9983-9999"}, + {"9984-00", "9984-49"}, + {"9984-500", "9984-899"}, + {"9984-9000", "9984-9999"}, + {"9985-0", "9985-4"}, + {"9985-50", "9985-79"}, + {"9985-800", "9985-899"}, + {"9985-9000", "9985-9999"}, + {"9986-00", "9986-39"}, + {"9986-400", "9986-899"}, + {"9986-9000", "9986-9399"}, + {"9986-940", "9986-969"}, + {"9986-97", "9986-99"}, + {"9987-00", "9987-39"}, + {"9987-400", "9987-879"}, + {"9987-8800", "9987-9999"}, + {"9988-0", "9988-2"}, + {"9988-30", "9988-54"}, + {"9988-550", "9988-749"}, + {"9988-7500", "9988-9999"}, + {"9989-0", "9989-0"}, + {"9989-100", "9989-199"}, + {"9989-2000", "9989-2999"}, + {"9989-30", "9989-59"}, + {"9989-600", "9989-949"}, + {"9989-9500", "9989-9999"}, + {"99901-00", "99901-49"}, + {"99901-500", "99901-799"}, + {"99901-80", "99901-99"}, + {"99903-0", "99903-1"}, + {"99903-20", "99903-89"}, + {"99903-900", "99903-999"}, + {"99904-0", "99904-5"}, + {"99904-60", "99904-89"}, + {"99904-900", "99904-999"}, + {"99905-0", "99905-3"}, + {"99905-40", "99905-79"}, + {"99905-800", "99905-999"}, + {"99906-0", "99906-2"}, + {"99906-30", "99906-59"}, + {"99906-600", "99906-699"}, + {"99906-70", "99906-89"}, + {"99906-90", "99906-94"}, + {"99906-950", "99906-999"}, + {"99908-0", "99908-0"}, + {"99908-10", "99908-89"}, + {"99908-900", "99908-999"}, + {"99909-0", "99909-3"}, + {"99909-40", "99909-94"}, + {"99909-950", "99909-999"}, + {"99910-0", "99910-2"}, + {"99910-30", "99910-89"}, + {"99910-900", "99910-999"}, + {"99911-00", "99911-59"}, + {"99911-600", "99911-999"}, + {"99912-0", "99912-3"}, + {"99912-400", "99912-599"}, + {"99912-60", "99912-89"}, + {"99912-900", "99912-999"}, + {"99913-0", "99913-2"}, + {"99913-30", "99913-35"}, + {"99913-600", "99913-604"}, + {"99914-0", "99914-4"}, + {"99914-50", "99914-89"}, + {"99914-900", "99914-999"}, + {"99915-0", "99915-4"}, + {"99915-50", "99915-79"}, + {"99915-800", "99915-999"}, + {"99916-0", "99916-2"}, + {"99916-30", "99916-69"}, + {"99916-700", "99916-999"}, + {"99917-0", "99917-2"}, + {"99917-30", "99917-89"}, + {"99917-900", "99917-999"}, + {"99918-0", "99918-3"}, + {"99918-40", "99918-79"}, + {"99918-800", "99918-999"}, + {"99919-0", "99919-2"}, + {"99919-300", "99919-399"}, + {"99919-40", "99919-69"}, + {"99919-900", "99919-999"}, + {"99920-0", "99920-4"}, + {"99920-50", "99920-89"}, + {"99920-900", "99920-999"}, + {"99921-0", "99921-1"}, + {"99921-20", "99921-69"}, + {"99921-700", "99921-799"}, + {"99921-8", "99921-8"}, + {"99921-90", "99921-99"}, + {"99922-0", "99922-3"}, + {"99922-40", "99922-69"}, + {"99922-700", "99922-999"}, + {"99923-0", "99923-1"}, + {"99923-20", "99923-79"}, + {"99923-800", "99923-999"}, + {"99924-0", "99924-1"}, + {"99924-20", "99924-79"}, + {"99924-800", "99924-999"}, + {"99925-0", "99925-3"}, + {"99925-40", "99925-79"}, + {"99925-800", "99925-999"}, + {"99926-0", "99926-0"}, + {"99926-10", "99926-59"}, + {"99926-600", "99926-999"}, + {"99927-0", "99927-2"}, + {"99927-30", "99927-59"}, + {"99927-600", "99927-999"}, + {"99928-0", "99928-0"}, + {"99928-10", "99928-79"}, + {"99928-800", "99928-999"}, + {"99929-0", "99929-4"}, + {"99929-50", "99929-79"}, + {"99929-800", "99929-999"}, + {"99930-0", "99930-4"}, + {"99930-50", "99930-79"}, + {"99930-800", "99930-999"}, + {"99931-0", "99931-4"}, + {"99931-50", "99931-79"}, + {"99931-800", "99931-999"}, + {"99932-0", "99932-0"}, + {"99932-10", "99932-59"}, + {"99932-600", "99932-699"}, + {"99932-7", "99932-7"}, + {"99932-80", "99932-99"}, + {"99933-0", "99933-2"}, + {"99933-30", "99933-59"}, + {"99933-600", "99933-999"}, + {"99934-0", "99934-1"}, + {"99934-20", "99934-79"}, + {"99934-800", "99934-999"}, + {"99935-0", "99935-2"}, + {"99935-30", "99935-59"}, + {"99935-600", "99935-699"}, + {"99935-7", "99935-8"}, + {"99935-90", "99935-99"}, + {"99936-0", "99936-0"}, + {"99936-10", "99936-59"}, + {"99936-600", "99936-999"}, + {"99937-0", "99937-1"}, + {"99937-20", "99937-59"}, + {"99937-600", "99937-999"}, + {"99938-0", "99938-1"}, + {"99938-20", "99938-59"}, + {"99938-600", "99938-899"}, + {"99938-90", "99938-99"}, + {"99939-0", "99939-5"}, + {"99939-60", "99939-89"}, + {"99939-900", "99939-999"}, + {"99940-0", "99940-0"}, + {"99940-10", "99940-69"}, + {"99940-700", "99940-999"}, + {"99941-0", "99941-2"}, + {"99941-30", "99941-79"}, + {"99941-800", "99941-999"}, + {"99942-0", "99942-4"}, + {"99942-50", "99942-79"}, + {"99942-800", "99942-999"}, + {"99943-0", "99943-2"}, + {"99943-30", "99943-59"}, + {"99943-600", "99943-999"}, + {"99944-0", "99944-4"}, + {"99944-50", "99944-79"}, + {"99944-800", "99944-999"}, + {"99945-0", "99945-5"}, + {"99945-60", "99945-89"}, + {"99945-900", "99945-999"}, + {"99946-0", "99946-2"}, + {"99946-30", "99946-59"}, + {"99946-600", "99946-999"}, + {"99947-0", "99947-2"}, + {"99947-30", "99947-69"}, + {"99947-700", "99947-999"}, + {"99948-0", "99948-4"}, + {"99948-50", "99948-79"}, + {"99948-800", "99948-999"}, + {"99949-0", "99949-1"}, + {"99949-20", "99949-89"}, + {"99949-900", "99949-999"}, + {"99950-0", "99950-4"}, + {"99950-50", "99950-79"}, + {"99950-800", "99950-999"}, + {"99952-0", "99952-4"}, + {"99952-50", "99952-79"}, + {"99952-800", "99952-999"}, + {"99953-0", "99953-2"}, + {"99953-30", "99953-79"}, + {"99953-800", "99953-939"}, + {"99953-94", "99953-99"}, + {"99954-0", "99954-2"}, + {"99954-30", "99954-69"}, + {"99954-700", "99954-999"}, + {"99955-0", "99955-1"}, + {"99955-20", "99955-59"}, + {"99955-600", "99955-799"}, + {"99955-80", "99955-89"}, + {"99955-90", "99955-99"}, + {"99956-00", "99956-59"}, + {"99956-600", "99956-859"}, + {"99956-86", "99956-99"}, + {"99957-0", "99957-1"}, + {"99957-20", "99957-79"}, + {"99957-800", "99957-999"}, + {"99958-0", "99958-4"}, + {"99958-50", "99958-94"}, + {"99958-950", "99958-999"}, + {"99959-0", "99959-2"}, + {"99959-30", "99959-59"}, + {"99959-600", "99959-999"}, + {"99960-0", "99960-0"}, + {"99960-10", "99960-94"}, + {"99960-950", "99960-999"}, + {"99961-0", "99961-3"}, + {"99961-40", "99961-89"}, + {"99961-900", "99961-999"}, + {"99962-0", "99962-4"}, + {"99962-50", "99962-79"}, + {"99962-800", "99962-999"}, + {"99963-00", "99963-49"}, + {"99963-500", "99963-999"}, + {"99964-0", "99964-1"}, + {"99964-20", "99964-79"}, + {"99964-800", "99964-999"}, + {"99965-0", "99965-3"}, + {"99965-40", "99965-79"}, + {"99965-800", "99965-999"}, + {"99966-0", "99966-2"}, + {"99966-30", "99966-69"}, + {"99966-700", "99966-799"}, + {"99967-0", "99967-1"}, + {"99967-20", "99967-59"}, + {"99967-600", "99967-899"}, + {NULL, NULL}, +}; + +/* + * For ISBN with prefix 979 + * Range Table as of 2010-Jul-29 + */ + +/* where the digit set begins, and how many of them are in the table */ +const unsigned ISBN_index_new[10][2] = { + {0, 0}, + {0, 5}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, +}; + +const char *ISBN_range_new[][2] = { + {"10-00", "10-19"}, + {"10-200", "10-699"}, + {"10-7000", "10-8999"}, + {"10-90000", "10-97599"}, + {"10-976000", "10-999999"}, + {NULL, NULL}, +}; diff --git a/contrib/isn/ISMN.h b/contrib/isn/ISMN.h new file mode 100644 index 0000000..281f2cd --- /dev/null +++ b/contrib/isn/ISMN.h @@ -0,0 +1,52 @@ +/* + * ISMN.h + * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) + * + * Information recompiled by Kronuz on November 12, 2004 + * http://www.ismn-international.org + * + * IDENTIFICATION + * contrib/isn/ISMN.h + * + * M-3452-4680-5 <=> (0)-3452-4680-5 <=> 0345246805 <=> 9790345246805 <=> 979-0-3452-4680-5 + * + * (M counts as 3) + * ISMN M 3 4 5 2 4 6 8 0 + * Weight 3 1 3 1 3 1 3 1 3 + * Product 9 + 3 + 12 + 5 + 6 + 4 + 18 + 8 + 0 = 65 + * 65 / 10 = 6 remainder 5 + * Check digit 10 - 5 = 5 + * => M-3452-4680-5 + * + * ISMN 9 7 9 0 3 4 5 2 4 6 8 0 + * Weight 1 3 1 3 1 3 1 3 1 3 1 3 + * Product 9 + 21 + 9 + 0 + 3 + 12 + 5 + 6 + 4 + 18 + 8 + 0 = 95 + * 95 / 10 = 9 remainder 5 + * Check digit 10 - 5 = 5 + * => 979-0-3452-4680-5 + * + * Since mod10(9*1 + 7*3 + 9*1 + 0*3) = mod10(M*3) = mod10(3*3) = 9; the check digit remains the same. + * + */ + +/* where the digit set begins, and how many of them are in the table */ +const unsigned ISMN_index[10][2] = { + {0, 5}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, + {5, 0}, +}; +const char *ISMN_range[][2] = { + {"0-000", "0-099"}, + {"0-1000", "0-3999"}, + {"0-40000", "0-69999"}, + {"0-700000", "0-899999"}, + {"0-9000000", "0-9999999"}, + {NULL, NULL} +}; diff --git a/contrib/isn/ISSN.h b/contrib/isn/ISSN.h new file mode 100644 index 0000000..585f0e2 --- /dev/null +++ b/contrib/isn/ISSN.h @@ -0,0 +1,49 @@ +/* + * ISSN.h + * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) + * + * Information recompiled by Kronuz on November 12, 2004 + * http://www.issn.org/ + * + * IDENTIFICATION + * contrib/isn/ISSN.h + * + * 1144-875X <=> 1144875(X) <=> 1144875 <=> (977)1144875 <=> 9771144875(00) <=> 977114487500(7) <=> 977-1144-875-00-7 + * + * + * ISSN 1 1 4 4 8 7 5 + * Weight 8 7 6 5 4 3 2 + * Product 8 + 7 + 24 + 20 + 32 + 21 + 10 = 122 + * 122 / 11 = 11 remainder 1 + * Check digit 11 - 1 = 10 = X + * => 1144-875X + * + * ISSN 9 7 7 1 1 4 4 8 7 5 0 0 + * Weight 1 3 1 3 1 3 1 3 1 3 1 3 + * Product 9 + 21 + 7 + 3 + 1 + 12 + 4 + 24 + 7 + 15 + 0 + 0 = 103 + * 103 / 10 = 10 remainder 3 + * Check digit 10 - 3 = 7 + * => 977-1144875-00-7 ?? <- supplemental number (number of the week, month, etc.) + * ^^ 00 for non-daily publications (01=Monday, 02=Tuesday, ...) + * + * The hyphenation is always in after the four digits of the ISSN code. + * + */ + +/* where the digit set begins, and how many of them are in the table */ +const unsigned ISSN_index[10][2] = { + {0, 1}, + {0, 1}, + {0, 1}, + {0, 1}, + {0, 1}, + {0, 1}, + {0, 1}, + {0, 1}, + {0, 1}, + {0, 1}, +}; +const char *ISSN_range[][2] = { + {"0000-000", "9999-999"}, + {NULL, NULL} +}; diff --git a/contrib/isn/Makefile b/contrib/isn/Makefile new file mode 100644 index 0000000..1037506 --- /dev/null +++ b/contrib/isn/Makefile @@ -0,0 +1,24 @@ +# contrib/isn/Makefile + +MODULES = isn + +EXTENSION = isn +DATA = isn--1.1.sql isn--1.1--1.2.sql \ + isn--1.0--1.1.sql +PGFILEDESC = "isn - data types for international product numbering standards" + +# the other .h files are data tables, we don't install those +HEADERS_isn = isn.h + +REGRESS = isn + +ifdef USE_PGXS +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) +else +subdir = contrib/isn +top_builddir = ../.. +include $(top_builddir)/src/Makefile.global +include $(top_srcdir)/contrib/contrib-global.mk +endif diff --git a/contrib/isn/UPC.h b/contrib/isn/UPC.h new file mode 100644 index 0000000..b95473e --- /dev/null +++ b/contrib/isn/UPC.h @@ -0,0 +1,28 @@ +/* + * ISSN.h + * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) + * + * No information available for UPC prefixes + * + * + * IDENTIFICATION + * contrib/isn/UPC.h + * + */ + +/* where the digit set begins, and how many of them are in the table */ +const unsigned UPC_index[10][2] = { + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, +}; +const char *UPC_range[][2] = { + {NULL, NULL} +}; diff --git a/contrib/isn/expected/isn.out b/contrib/isn/expected/isn.out new file mode 100644 index 0000000..18fe37a --- /dev/null +++ b/contrib/isn/expected/isn.out @@ -0,0 +1,266 @@ +-- +-- Test ISN extension +-- +CREATE EXTENSION isn; +-- Check whether any of our opclasses fail amvalidate +-- ... they will, because of missing cross-type operators +SELECT amname, opcname +FROM (SELECT amname, opcname, opc.oid + FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod + WHERE opc.oid >= 16384 + ORDER BY 1, 2 OFFSET 0) ss +WHERE NOT amvalidate(oid); +INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s) +INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s) + amname | opcname +--------+------------ + btree | ean13_ops + btree | isbn13_ops + btree | isbn_ops + btree | ismn13_ops + btree | ismn_ops + btree | issn13_ops + btree | issn_ops + btree | upc_ops + hash | ean13_ops + hash | isbn13_ops + hash | isbn_ops + hash | ismn13_ops + hash | ismn_ops + hash | issn13_ops + hash | issn_ops + hash | upc_ops +(16 rows) + +-- +-- test valid conversions +-- +SELECT '9780123456786'::EAN13, -- old book + '9790123456785'::EAN13, -- music + '9791234567896'::EAN13, -- new book + '9771234567898'::EAN13, -- serial + '0123456789012'::EAN13, -- upc + '1234567890128'::EAN13; + ean13 | ean13 | ean13 | ean13 | ean13 | ean13 +-------------------+-------------------+-----------------+-------------------+-----------------+----------------- + 978-0-12-345678-6 | 979-0-1234-5678-5 | 979-123456789-6 | 977-1234-567-89-8 | 012-345678901-2 | 123-456789012-8 +(1 row) + +SELECT '9780123456786'::ISBN, + '123456789X'::ISBN, + '9780123456786'::ISBN13::ISBN, + '9780123456786'::EAN13::ISBN; + isbn | isbn | isbn | isbn +---------------+---------------+---------------+--------------- + 0-12-345678-9 | 1-234-56789-X | 0-12-345678-9 | 0-12-345678-9 +(1 row) + +SELECT -- new books, shown as ISBN13 even for ISBN... + '9791234567896'::ISBN, + '9791234567896'::ISBN13::ISBN, + '9791234567896'::EAN13::ISBN; + isbn | isbn | isbn +-----------------+-----------------+----------------- + 979-123456789-6 | 979-123456789-6 | 979-123456789-6 +(1 row) + +SELECT '9780123456786'::ISBN13, + '123456789X'::ISBN13, + '9791234567896'::ISBN13, + '9791234567896'::EAN13::ISBN13; + isbn13 | isbn13 | isbn13 | isbn13 +-------------------+-------------------+-----------------+----------------- + 978-0-12-345678-6 | 978-1-234-56789-7 | 979-123456789-6 | 979-123456789-6 +(1 row) + +SELECT '9790123456785'::ISMN, + '9790123456785'::EAN13::ISMN, + 'M123456785'::ISMN, + 'M-1234-5678-5'::ISMN; + ismn | ismn | ismn | ismn +---------------+---------------+---------------+--------------- + M-1234-5678-5 | M-1234-5678-5 | M-1234-5678-5 | M-1234-5678-5 +(1 row) + +SELECT '9790123456785'::ISMN13, + 'M123456785'::ISMN13, + 'M-1234-5678-5'::ISMN13; + ismn13 | ismn13 | ismn13 +-------------------+-------------------+------------------- + 979-0-1234-5678-5 | 979-0-1234-5678-5 | 979-0-1234-5678-5 +(1 row) + +SELECT '9771234567003'::ISSN, + '12345679'::ISSN; + issn | issn +-----------+----------- + 1234-5679 | 1234-5679 +(1 row) + +SELECT '9771234567003'::ISSN13, + '12345679'::ISSN13, + '9771234567898'::ISSN13, + '9771234567898'::EAN13::ISSN13; + issn13 | issn13 | issn13 | issn13 +-------------------+-------------------+-------------------+------------------- + 977-1234-567-00-3 | 977-1234-567-00-3 | 977-1234-567-89-8 | 977-1234-567-89-8 +(1 row) + +SELECT '0123456789012'::UPC, + '0123456789012'::EAN13::UPC; + upc | upc +--------------+-------------- + 123456789012 | 123456789012 +(1 row) + +-- +-- test invalid checksums +-- +SELECT '1234567890'::ISBN; +ERROR: invalid check digit for ISBN number: "1234567890", should be X +LINE 1: SELECT '1234567890'::ISBN; + ^ +SELECT 'M123456780'::ISMN; +ERROR: invalid check digit for ISMN number: "M123456780", should be 5 +LINE 1: SELECT 'M123456780'::ISMN; + ^ +SELECT '12345670'::ISSN; +ERROR: invalid check digit for ISSN number: "12345670", should be 9 +LINE 1: SELECT '12345670'::ISSN; + ^ +SELECT '9780123456780'::ISBN; +ERROR: invalid check digit for ISBN number: "9780123456780", should be 6 +LINE 1: SELECT '9780123456780'::ISBN; + ^ +SELECT '9791234567890'::ISBN13; +ERROR: invalid check digit for ISBN number: "9791234567890", should be 6 +LINE 1: SELECT '9791234567890'::ISBN13; + ^ +SELECT '0123456789010'::UPC; +ERROR: invalid check digit for UPC number: "0123456789010", should be 2 +LINE 1: SELECT '0123456789010'::UPC; + ^ +SELECT '1234567890120'::EAN13; +ERROR: invalid check digit for EAN13 number: "1234567890120", should be 8 +LINE 1: SELECT '1234567890120'::EAN13; + ^ +-- +-- test invalid conversions +-- +SELECT '9790123456785'::ISBN; -- not a book +ERROR: cannot cast ISMN to ISBN for number: "9790123456785" +LINE 1: SELECT '9790123456785'::ISBN; + ^ +SELECT '9771234567898'::ISBN; -- not a book +ERROR: cannot cast ISSN to ISBN for number: "9771234567898" +LINE 1: SELECT '9771234567898'::ISBN; + ^ +SELECT '0123456789012'::ISBN; -- not a book +ERROR: cannot cast UPC to ISBN for number: "0123456789012" +LINE 1: SELECT '0123456789012'::ISBN; + ^ +SELECT '9790123456785'::ISBN13; -- not a book +ERROR: cannot cast ISMN to ISBN for number: "9790123456785" +LINE 1: SELECT '9790123456785'::ISBN13; + ^ +SELECT '9771234567898'::ISBN13; -- not a book +ERROR: cannot cast ISSN to ISBN for number: "9771234567898" +LINE 1: SELECT '9771234567898'::ISBN13; + ^ +SELECT '0123456789012'::ISBN13; -- not a book +ERROR: cannot cast UPC to ISBN for number: "0123456789012" +LINE 1: SELECT '0123456789012'::ISBN13; + ^ +SELECT '9780123456786'::ISMN; -- not music +ERROR: cannot cast ISBN to ISMN for number: "9780123456786" +LINE 1: SELECT '9780123456786'::ISMN; + ^ +SELECT '9771234567898'::ISMN; -- not music +ERROR: cannot cast ISSN to ISMN for number: "9771234567898" +LINE 1: SELECT '9771234567898'::ISMN; + ^ +SELECT '9791234567896'::ISMN; -- not music +ERROR: cannot cast ISBN to ISMN for number: "9791234567896" +LINE 1: SELECT '9791234567896'::ISMN; + ^ +SELECT '0123456789012'::ISMN; -- not music +ERROR: cannot cast UPC to ISMN for number: "0123456789012" +LINE 1: SELECT '0123456789012'::ISMN; + ^ +SELECT '9780123456786'::ISSN; -- not serial +ERROR: cannot cast ISBN to ISSN for number: "9780123456786" +LINE 1: SELECT '9780123456786'::ISSN; + ^ +SELECT '9790123456785'::ISSN; -- not serial +ERROR: cannot cast ISMN to ISSN for number: "9790123456785" +LINE 1: SELECT '9790123456785'::ISSN; + ^ +SELECT '9791234567896'::ISSN; -- not serial +ERROR: cannot cast ISBN to ISSN for number: "9791234567896" +LINE 1: SELECT '9791234567896'::ISSN; + ^ +SELECT '0123456789012'::ISSN; -- not serial +ERROR: cannot cast UPC to ISSN for number: "0123456789012" +LINE 1: SELECT '0123456789012'::ISSN; + ^ +SELECT '9780123456786'::UPC; -- not a product +ERROR: cannot cast ISBN to UPC for number: "9780123456786" +LINE 1: SELECT '9780123456786'::UPC; + ^ +SELECT '9771234567898'::UPC; -- not a product +ERROR: cannot cast ISSN to UPC for number: "9771234567898" +LINE 1: SELECT '9771234567898'::UPC; + ^ +SELECT '9790123456785'::UPC; -- not a product +ERROR: cannot cast ISMN to UPC for number: "9790123456785" +LINE 1: SELECT '9790123456785'::UPC; + ^ +SELECT '9791234567896'::UPC; -- not a product +ERROR: cannot cast ISBN to UPC for number: "9791234567896" +LINE 1: SELECT '9791234567896'::UPC; + ^ +SELECT 'postgresql...'::EAN13; +ERROR: invalid input syntax for EAN13 number: "postgresql..." +LINE 1: SELECT 'postgresql...'::EAN13; + ^ +SELECT 'postgresql...'::ISBN; +ERROR: invalid input syntax for ISBN number: "postgresql..." +LINE 1: SELECT 'postgresql...'::ISBN; + ^ +SELECT 9780123456786::EAN13; +ERROR: cannot cast type bigint to ean13 +LINE 1: SELECT 9780123456786::EAN13; + ^ +SELECT 9780123456786::ISBN; +ERROR: cannot cast type bigint to isbn +LINE 1: SELECT 9780123456786::ISBN; + ^ +-- +-- test some comparisons, must yield true +-- +SELECT '12345679'::ISSN = '9771234567003'::EAN13 AS "ok", + 'M-1234-5678-5'::ISMN = '9790123456785'::EAN13 AS "ok", + '9791234567896'::EAN13 != '123456789X'::ISBN AS "nope"; + ok | ok | nope +----+----+------ + t | t | t +(1 row) + +-- +-- cleanup +-- +DROP EXTENSION isn; diff --git a/contrib/isn/isn--1.0--1.1.sql b/contrib/isn/isn--1.0--1.1.sql new file mode 100644 index 0000000..6f1ccb0 --- /dev/null +++ b/contrib/isn/isn--1.0--1.1.sql @@ -0,0 +1,250 @@ +/* contrib/isn/isn--1.0--1.1.sql */ + +-- complain if script is sourced in psql, rather than via ALTER EXTENSION +\echo Use "ALTER EXTENSION isn UPDATE TO '1.1'" to load this file. \quit + +ALTER FUNCTION ean13_in(cstring) PARALLEL SAFE; +ALTER FUNCTION ean13_out(ean13) PARALLEL SAFE; +ALTER FUNCTION isbn13_in(cstring) PARALLEL SAFE; +ALTER FUNCTION ean13_out(isbn13) PARALLEL SAFE; +ALTER FUNCTION ismn13_in(cstring) PARALLEL SAFE; +ALTER FUNCTION ean13_out(ismn13) PARALLEL SAFE; +ALTER FUNCTION issn13_in(cstring) PARALLEL SAFE; +ALTER FUNCTION ean13_out(issn13) PARALLEL SAFE; +ALTER FUNCTION isbn_in(cstring) PARALLEL SAFE; +ALTER FUNCTION isn_out(isbn) PARALLEL SAFE; +ALTER FUNCTION ismn_in(cstring) PARALLEL SAFE; +ALTER FUNCTION isn_out(ismn) PARALLEL SAFE; +ALTER FUNCTION issn_in(cstring) PARALLEL SAFE; +ALTER FUNCTION isn_out(issn) PARALLEL SAFE; +ALTER FUNCTION upc_in(cstring) PARALLEL SAFE; +ALTER FUNCTION isn_out(upc) PARALLEL SAFE; +ALTER FUNCTION isnlt(ean13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnle(ean13, ean13) PARALLEL SAFE; +ALTER FUNCTION isneq(ean13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnge(ean13, ean13) PARALLEL SAFE; +ALTER FUNCTION isngt(ean13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnne(ean13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnlt(ean13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnle(ean13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isneq(ean13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnge(ean13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isngt(ean13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnne(ean13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(ean13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnle(ean13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isneq(ean13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnge(ean13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isngt(ean13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnne(ean13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(ean13, issn13) PARALLEL SAFE; +ALTER FUNCTION isnle(ean13, issn13) PARALLEL SAFE; +ALTER FUNCTION isneq(ean13, issn13) PARALLEL SAFE; +ALTER FUNCTION isnge(ean13, issn13) PARALLEL SAFE; +ALTER FUNCTION isngt(ean13, issn13) PARALLEL SAFE; +ALTER FUNCTION isnne(ean13, issn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(ean13, isbn) PARALLEL SAFE; +ALTER FUNCTION isnle(ean13, isbn) PARALLEL SAFE; +ALTER FUNCTION isneq(ean13, isbn) PARALLEL SAFE; +ALTER FUNCTION isnge(ean13, isbn) PARALLEL SAFE; +ALTER FUNCTION isngt(ean13, isbn) PARALLEL SAFE; +ALTER FUNCTION isnne(ean13, isbn) PARALLEL SAFE; +ALTER FUNCTION isnlt(ean13, ismn) PARALLEL SAFE; +ALTER FUNCTION isnle(ean13, ismn) PARALLEL SAFE; +ALTER FUNCTION isneq(ean13, ismn) PARALLEL SAFE; +ALTER FUNCTION isnge(ean13, ismn) PARALLEL SAFE; +ALTER FUNCTION isngt(ean13, ismn) PARALLEL SAFE; +ALTER FUNCTION isnne(ean13, ismn) PARALLEL SAFE; +ALTER FUNCTION isnlt(ean13, issn) PARALLEL SAFE; +ALTER FUNCTION isnle(ean13, issn) PARALLEL SAFE; +ALTER FUNCTION isneq(ean13, issn) PARALLEL SAFE; +ALTER FUNCTION isnge(ean13, issn) PARALLEL SAFE; +ALTER FUNCTION isngt(ean13, issn) PARALLEL SAFE; +ALTER FUNCTION isnne(ean13, issn) PARALLEL SAFE; +ALTER FUNCTION isnlt(ean13, upc) PARALLEL SAFE; +ALTER FUNCTION isnle(ean13, upc) PARALLEL SAFE; +ALTER FUNCTION isneq(ean13, upc) PARALLEL SAFE; +ALTER FUNCTION isnge(ean13, upc) PARALLEL SAFE; +ALTER FUNCTION isngt(ean13, upc) PARALLEL SAFE; +ALTER FUNCTION isnne(ean13, upc) PARALLEL SAFE; +ALTER FUNCTION isnlt(isbn13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnle(isbn13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isneq(isbn13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnge(isbn13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isngt(isbn13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnne(isbn13, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(isbn13, isbn) PARALLEL SAFE; +ALTER FUNCTION isnle(isbn13, isbn) PARALLEL SAFE; +ALTER FUNCTION isneq(isbn13, isbn) PARALLEL SAFE; +ALTER FUNCTION isnge(isbn13, isbn) PARALLEL SAFE; +ALTER FUNCTION isngt(isbn13, isbn) PARALLEL SAFE; +ALTER FUNCTION isnne(isbn13, isbn) PARALLEL SAFE; +ALTER FUNCTION isnlt(isbn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnle(isbn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isneq(isbn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnge(isbn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isngt(isbn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnne(isbn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnlt(isbn, isbn) PARALLEL SAFE; +ALTER FUNCTION isnle(isbn, isbn) PARALLEL SAFE; +ALTER FUNCTION isneq(isbn, isbn) PARALLEL SAFE; +ALTER FUNCTION isnge(isbn, isbn) PARALLEL SAFE; +ALTER FUNCTION isngt(isbn, isbn) PARALLEL SAFE; +ALTER FUNCTION isnne(isbn, isbn) PARALLEL SAFE; +ALTER FUNCTION isnlt(isbn, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnle(isbn, isbn13) PARALLEL SAFE; +ALTER FUNCTION isneq(isbn, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnge(isbn, isbn13) PARALLEL SAFE; +ALTER FUNCTION isngt(isbn, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnne(isbn, isbn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(isbn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnle(isbn, ean13) PARALLEL SAFE; +ALTER FUNCTION isneq(isbn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnge(isbn, ean13) PARALLEL SAFE; +ALTER FUNCTION isngt(isbn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnne(isbn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnlt(ismn13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnle(ismn13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isneq(ismn13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnge(ismn13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isngt(ismn13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnne(ismn13, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(ismn13, ismn) PARALLEL SAFE; +ALTER FUNCTION isnle(ismn13, ismn) PARALLEL SAFE; +ALTER FUNCTION isneq(ismn13, ismn) PARALLEL SAFE; +ALTER FUNCTION isnge(ismn13, ismn) PARALLEL SAFE; +ALTER FUNCTION isngt(ismn13, ismn) PARALLEL SAFE; +ALTER FUNCTION isnne(ismn13, ismn) PARALLEL SAFE; +ALTER FUNCTION isnlt(ismn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnle(ismn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isneq(ismn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnge(ismn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isngt(ismn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnne(ismn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnlt(ismn, ismn) PARALLEL SAFE; +ALTER FUNCTION isnle(ismn, ismn) PARALLEL SAFE; +ALTER FUNCTION isneq(ismn, ismn) PARALLEL SAFE; +ALTER FUNCTION isnge(ismn, ismn) PARALLEL SAFE; +ALTER FUNCTION isngt(ismn, ismn) PARALLEL SAFE; +ALTER FUNCTION isnne(ismn, ismn) PARALLEL SAFE; +ALTER FUNCTION isnlt(ismn, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnle(ismn, ismn13) PARALLEL SAFE; +ALTER FUNCTION isneq(ismn, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnge(ismn, ismn13) PARALLEL SAFE; +ALTER FUNCTION isngt(ismn, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnne(ismn, ismn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(ismn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnle(ismn, ean13) PARALLEL SAFE; +ALTER FUNCTION isneq(ismn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnge(ismn, ean13) PARALLEL SAFE; +ALTER FUNCTION isngt(ismn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnne(ismn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnlt(issn13, issn13) PARALLEL SAFE; +ALTER FUNCTION isnle(issn13, issn13) PARALLEL SAFE; +ALTER FUNCTION isneq(issn13, issn13) PARALLEL SAFE; +ALTER FUNCTION isnge(issn13, issn13) PARALLEL SAFE; +ALTER FUNCTION isngt(issn13, issn13) PARALLEL SAFE; +ALTER FUNCTION isnne(issn13, issn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(issn13, issn) PARALLEL SAFE; +ALTER FUNCTION isnle(issn13, issn) PARALLEL SAFE; +ALTER FUNCTION isneq(issn13, issn) PARALLEL SAFE; +ALTER FUNCTION isnge(issn13, issn) PARALLEL SAFE; +ALTER FUNCTION isngt(issn13, issn) PARALLEL SAFE; +ALTER FUNCTION isnne(issn13, issn) PARALLEL SAFE; +ALTER FUNCTION isnlt(issn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnle(issn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isneq(issn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnge(issn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isngt(issn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnne(issn13, ean13) PARALLEL SAFE; +ALTER FUNCTION isnlt(issn, issn) PARALLEL SAFE; +ALTER FUNCTION isnle(issn, issn) PARALLEL SAFE; +ALTER FUNCTION isneq(issn, issn) PARALLEL SAFE; +ALTER FUNCTION isnge(issn, issn) PARALLEL SAFE; +ALTER FUNCTION isngt(issn, issn) PARALLEL SAFE; +ALTER FUNCTION isnne(issn, issn) PARALLEL SAFE; +ALTER FUNCTION isnlt(issn, issn13) PARALLEL SAFE; +ALTER FUNCTION isnle(issn, issn13) PARALLEL SAFE; +ALTER FUNCTION isneq(issn, issn13) PARALLEL SAFE; +ALTER FUNCTION isnge(issn, issn13) PARALLEL SAFE; +ALTER FUNCTION isngt(issn, issn13) PARALLEL SAFE; +ALTER FUNCTION isnne(issn, issn13) PARALLEL SAFE; +ALTER FUNCTION isnlt(issn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnle(issn, ean13) PARALLEL SAFE; +ALTER FUNCTION isneq(issn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnge(issn, ean13) PARALLEL SAFE; +ALTER FUNCTION isngt(issn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnne(issn, ean13) PARALLEL SAFE; +ALTER FUNCTION isnlt(upc, upc) PARALLEL SAFE; +ALTER FUNCTION isnle(upc, upc) PARALLEL SAFE; +ALTER FUNCTION isneq(upc, upc) PARALLEL SAFE; +ALTER FUNCTION isnge(upc, upc) PARALLEL SAFE; +ALTER FUNCTION isngt(upc, upc) PARALLEL SAFE; +ALTER FUNCTION isnne(upc, upc) PARALLEL SAFE; +ALTER FUNCTION isnlt(upc, ean13) PARALLEL SAFE; +ALTER FUNCTION isnle(upc, ean13) PARALLEL SAFE; +ALTER FUNCTION isneq(upc, ean13) PARALLEL SAFE; +ALTER FUNCTION isnge(upc, ean13) PARALLEL SAFE; +ALTER FUNCTION isngt(upc, ean13) PARALLEL SAFE; +ALTER FUNCTION isnne(upc, ean13) PARALLEL SAFE; +ALTER FUNCTION btean13cmp(ean13, ean13) PARALLEL SAFE; +ALTER FUNCTION hashean13(ean13) PARALLEL SAFE; +ALTER FUNCTION btean13cmp(ean13, isbn13) PARALLEL SAFE; +ALTER FUNCTION btean13cmp(ean13, ismn13) PARALLEL SAFE; +ALTER FUNCTION btean13cmp(ean13, issn13) PARALLEL SAFE; +ALTER FUNCTION btean13cmp(ean13, isbn) PARALLEL SAFE; +ALTER FUNCTION btean13cmp(ean13, ismn) PARALLEL SAFE; +ALTER FUNCTION btean13cmp(ean13, issn) PARALLEL SAFE; +ALTER FUNCTION btean13cmp(ean13, upc) PARALLEL SAFE; +ALTER FUNCTION btisbn13cmp(isbn13, isbn13) PARALLEL SAFE; +ALTER FUNCTION hashisbn13(isbn13) PARALLEL SAFE; +ALTER FUNCTION btisbn13cmp(isbn13, ean13) PARALLEL SAFE; +ALTER FUNCTION btisbn13cmp(isbn13, isbn) PARALLEL SAFE; +ALTER FUNCTION btisbncmp(isbn, isbn) PARALLEL SAFE; +ALTER FUNCTION hashisbn(isbn) PARALLEL SAFE; +ALTER FUNCTION btisbncmp(isbn, ean13) PARALLEL SAFE; +ALTER FUNCTION btisbncmp(isbn, isbn13) PARALLEL SAFE; +ALTER FUNCTION btismn13cmp(ismn13, ismn13) PARALLEL SAFE; +ALTER FUNCTION hashismn13(ismn13) PARALLEL SAFE; +ALTER FUNCTION btismn13cmp(ismn13, ean13) PARALLEL SAFE; +ALTER FUNCTION btismn13cmp(ismn13, ismn) PARALLEL SAFE; +ALTER FUNCTION btismncmp(ismn, ismn) PARALLEL SAFE; +ALTER FUNCTION hashismn(ismn) PARALLEL SAFE; +ALTER FUNCTION btismncmp(ismn, ean13) PARALLEL SAFE; +ALTER FUNCTION btismncmp(ismn, ismn13) PARALLEL SAFE; +ALTER FUNCTION btissn13cmp(issn13, issn13) PARALLEL SAFE; +ALTER FUNCTION hashissn13(issn13) PARALLEL SAFE; +ALTER FUNCTION btissn13cmp(issn13, ean13) PARALLEL SAFE; +ALTER FUNCTION btissn13cmp(issn13, issn) PARALLEL SAFE; +ALTER FUNCTION btissncmp(issn, issn) PARALLEL SAFE; +ALTER FUNCTION hashissn(issn) PARALLEL SAFE; +ALTER FUNCTION btissncmp(issn, ean13) PARALLEL SAFE; +ALTER FUNCTION btissncmp(issn, issn13) PARALLEL SAFE; +ALTER FUNCTION btupccmp(upc, upc) PARALLEL SAFE; +ALTER FUNCTION hashupc(upc) PARALLEL SAFE; +ALTER FUNCTION btupccmp(upc, ean13) PARALLEL SAFE; +ALTER FUNCTION isbn13(ean13) PARALLEL SAFE; +ALTER FUNCTION ismn13(ean13) PARALLEL SAFE; +ALTER FUNCTION issn13(ean13) PARALLEL SAFE; +ALTER FUNCTION isbn(ean13) PARALLEL SAFE; +ALTER FUNCTION ismn(ean13) PARALLEL SAFE; +ALTER FUNCTION issn(ean13) PARALLEL SAFE; +ALTER FUNCTION upc(ean13) PARALLEL SAFE; +ALTER FUNCTION make_valid(ean13) PARALLEL SAFE; +ALTER FUNCTION make_valid(isbn13) PARALLEL SAFE; +ALTER FUNCTION make_valid(ismn13) PARALLEL SAFE; +ALTER FUNCTION make_valid(issn13) PARALLEL SAFE; +ALTER FUNCTION make_valid(isbn) PARALLEL SAFE; +ALTER FUNCTION make_valid(ismn) PARALLEL SAFE; +ALTER FUNCTION make_valid(issn) PARALLEL SAFE; +ALTER FUNCTION make_valid(upc) PARALLEL SAFE; +ALTER FUNCTION is_valid(ean13) PARALLEL SAFE; +ALTER FUNCTION is_valid(isbn13) PARALLEL SAFE; +ALTER FUNCTION is_valid(ismn13) PARALLEL SAFE; +ALTER FUNCTION is_valid(issn13) PARALLEL SAFE; +ALTER FUNCTION is_valid(isbn) PARALLEL SAFE; +ALTER FUNCTION is_valid(ismn) PARALLEL SAFE; +ALTER FUNCTION is_valid(issn) PARALLEL SAFE; +ALTER FUNCTION is_valid(upc) PARALLEL SAFE; +ALTER FUNCTION isn_weak(boolean) PARALLEL RESTRICTED; +ALTER FUNCTION isn_weak() PARALLEL RESTRICTED; diff --git a/contrib/isn/isn--1.1--1.2.sql b/contrib/isn/isn--1.1--1.2.sql new file mode 100644 index 0000000..d626a5f --- /dev/null +++ b/contrib/isn/isn--1.1--1.2.sql @@ -0,0 +1,228 @@ +/* contrib/isn/isn--1.1--1.2.sql */ + +-- complain if script is sourced in psql, rather than via ALTER EXTENSION +\echo Use "ALTER EXTENSION isn UPDATE TO '1.2'" to load this file. \quit + +ALTER OPERATOR <= (ean13, ean13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ean13, ean13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ean13, isbn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ean13, isbn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (isbn13, ean13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (isbn13, ean13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ean13, ismn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ean13, ismn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ismn13, ean13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ismn13, ean13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ean13, issn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ean13, issn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ean13, isbn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ean13, isbn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ean13, ismn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ean13, ismn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ean13, issn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ean13, issn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ean13, upc) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ean13, upc) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (isbn13, isbn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (isbn13, isbn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (isbn13, isbn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (isbn13, isbn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (isbn, isbn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (isbn, isbn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (isbn, isbn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (isbn, isbn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (isbn, ean13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (isbn, ean13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ismn13, ismn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ismn13, ismn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ismn13, ismn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ismn13, ismn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ismn, ismn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ismn, ismn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ismn, ismn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ismn, ismn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (ismn, ean13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (ismn, ean13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (issn13, issn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (issn13, issn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (issn13, issn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (issn13, issn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (issn13, ean13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (issn13, ean13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (issn, issn) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (issn, issn) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (issn, issn13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (issn, issn13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (issn, ean13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (issn, ean13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (upc, upc) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (upc, upc) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); + +ALTER OPERATOR <= (upc, ean13) SET ( + RESTRICT = scalarlesel, + JOIN = scalarlejoinsel); + +ALTER OPERATOR >= (upc, ean13) SET ( + RESTRICT = scalargesel, + JOIN = scalargejoinsel); diff --git a/contrib/isn/isn--1.1.sql b/contrib/isn/isn--1.1.sql new file mode 100644 index 0000000..5206961 --- /dev/null +++ b/contrib/isn/isn--1.1.sql @@ -0,0 +1,3434 @@ +/* contrib/isn/isn--1.1.sql */ + +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION isn" to load this file. \quit + +-- Example: +-- create table test ( id isbn ); +-- insert into test values('978-0-393-04002-9'); +-- +-- select isbn('978-0-393-04002-9'); +-- select isbn13('0-901690-54-6'); +-- + +-- +-- Input and output functions and data types: +-- +--------------------------------------------------- +CREATE FUNCTION ean13_in(cstring) + RETURNS ean13 + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION ean13_out(ean13) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE TYPE ean13 ( + INPUT = ean13_in, + OUTPUT = ean13_out, + LIKE = pg_catalog.int8 +); +COMMENT ON TYPE ean13 + IS 'International European Article Number (EAN13)'; + +CREATE FUNCTION isbn13_in(cstring) + RETURNS isbn13 + AS 'MODULE_PATHNAME', 'isbn_in' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION ean13_out(isbn13) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE TYPE isbn13 ( + INPUT = isbn13_in, + OUTPUT = ean13_out, + LIKE = pg_catalog.int8 +); +COMMENT ON TYPE isbn13 + IS 'International Standard Book Number 13 (ISBN13)'; + +CREATE FUNCTION ismn13_in(cstring) + RETURNS ismn13 + AS 'MODULE_PATHNAME', 'ismn_in' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION ean13_out(ismn13) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE TYPE ismn13 ( + INPUT = ismn13_in, + OUTPUT = ean13_out, + LIKE = pg_catalog.int8 +); +COMMENT ON TYPE ismn13 + IS 'International Standard Music Number 13 (ISMN13)'; + +CREATE FUNCTION issn13_in(cstring) + RETURNS issn13 + AS 'MODULE_PATHNAME', 'issn_in' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION ean13_out(issn13) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE TYPE issn13 ( + INPUT = issn13_in, + OUTPUT = ean13_out, + LIKE = pg_catalog.int8 +); +COMMENT ON TYPE issn13 + IS 'International Standard Serial Number 13 (ISSN13)'; + +-- Short format: + +CREATE FUNCTION isbn_in(cstring) + RETURNS isbn + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isn_out(isbn) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE TYPE isbn ( + INPUT = isbn_in, + OUTPUT = isn_out, + LIKE = pg_catalog.int8 +); +COMMENT ON TYPE isbn + IS 'International Standard Book Number (ISBN)'; + +CREATE FUNCTION ismn_in(cstring) + RETURNS ismn + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isn_out(ismn) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE TYPE ismn ( + INPUT = ismn_in, + OUTPUT = isn_out, + LIKE = pg_catalog.int8 +); +COMMENT ON TYPE ismn + IS 'International Standard Music Number (ISMN)'; + +CREATE FUNCTION issn_in(cstring) + RETURNS issn + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isn_out(issn) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE TYPE issn ( + INPUT = issn_in, + OUTPUT = isn_out, + LIKE = pg_catalog.int8 +); +COMMENT ON TYPE issn + IS 'International Standard Serial Number (ISSN)'; + +CREATE FUNCTION upc_in(cstring) + RETURNS upc + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isn_out(upc) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE TYPE upc ( + INPUT = upc_in, + OUTPUT = isn_out, + LIKE = pg_catalog.int8 +); +COMMENT ON TYPE upc + IS 'Universal Product Code (UPC)'; + +-- +-- Operator functions: +-- +--------------------------------------------------- +-- EAN13: +CREATE FUNCTION isnlt(ean13, ean13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ean13, ean13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ean13, ean13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ean13, ean13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ean13, ean13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ean13, ean13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ean13, isbn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ean13, isbn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ean13, isbn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ean13, isbn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ean13, isbn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ean13, isbn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ean13, ismn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ean13, ismn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ean13, ismn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ean13, ismn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ean13, ismn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ean13, ismn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ean13, issn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ean13, issn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ean13, issn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ean13, issn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ean13, issn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ean13, issn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ean13, isbn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ean13, isbn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ean13, isbn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ean13, isbn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ean13, isbn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ean13, isbn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ean13, ismn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ean13, ismn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ean13, ismn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ean13, ismn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ean13, ismn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ean13, ismn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ean13, issn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ean13, issn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ean13, issn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ean13, issn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ean13, issn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ean13, issn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ean13, upc) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ean13, upc) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ean13, upc) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ean13, upc) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ean13, upc) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ean13, upc) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +--------------------------------------------------- +-- ISBN13: +CREATE FUNCTION isnlt(isbn13, isbn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(isbn13, isbn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(isbn13, isbn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(isbn13, isbn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(isbn13, isbn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(isbn13, isbn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(isbn13, isbn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(isbn13, isbn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(isbn13, isbn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(isbn13, isbn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(isbn13, isbn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(isbn13, isbn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(isbn13, ean13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(isbn13, ean13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(isbn13, ean13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(isbn13, ean13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(isbn13, ean13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(isbn13, ean13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +--------------------------------------------------- +-- ISBN: +CREATE FUNCTION isnlt(isbn, isbn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(isbn, isbn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(isbn, isbn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(isbn, isbn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(isbn, isbn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(isbn, isbn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(isbn, isbn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(isbn, isbn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(isbn, isbn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(isbn, isbn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(isbn, isbn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(isbn, isbn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(isbn, ean13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(isbn, ean13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(isbn, ean13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(isbn, ean13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(isbn, ean13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(isbn, ean13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +--------------------------------------------------- +-- ISMN13: +CREATE FUNCTION isnlt(ismn13, ismn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ismn13, ismn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ismn13, ismn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ismn13, ismn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ismn13, ismn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ismn13, ismn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ismn13, ismn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ismn13, ismn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ismn13, ismn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ismn13, ismn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ismn13, ismn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ismn13, ismn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ismn13, ean13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ismn13, ean13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ismn13, ean13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ismn13, ean13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ismn13, ean13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ismn13, ean13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +--------------------------------------------------- +-- ISMN: +CREATE FUNCTION isnlt(ismn, ismn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ismn, ismn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ismn, ismn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ismn, ismn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ismn, ismn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ismn, ismn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ismn, ismn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ismn, ismn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ismn, ismn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ismn, ismn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ismn, ismn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ismn, ismn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(ismn, ean13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(ismn, ean13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(ismn, ean13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(ismn, ean13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(ismn, ean13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(ismn, ean13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +--------------------------------------------------- +-- ISSN13: +CREATE FUNCTION isnlt(issn13, issn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(issn13, issn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(issn13, issn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(issn13, issn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(issn13, issn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(issn13, issn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(issn13, issn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(issn13, issn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(issn13, issn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(issn13, issn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(issn13, issn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(issn13, issn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(issn13, ean13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(issn13, ean13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(issn13, ean13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(issn13, ean13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(issn13, ean13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(issn13, ean13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +--------------------------------------------------- +-- ISSN: +CREATE FUNCTION isnlt(issn, issn) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(issn, issn) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(issn, issn) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(issn, issn) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(issn, issn) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(issn, issn) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(issn, issn13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(issn, issn13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(issn, issn13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(issn, issn13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(issn, issn13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(issn, issn13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(issn, ean13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(issn, ean13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(issn, ean13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(issn, ean13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(issn, ean13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(issn, ean13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +--------------------------------------------------- +-- UPC: +CREATE FUNCTION isnlt(upc, upc) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(upc, upc) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(upc, upc) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(upc, upc) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(upc, upc) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(upc, upc) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION isnlt(upc, ean13) + RETURNS boolean + AS 'int8lt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnle(upc, ean13) + RETURNS boolean + AS 'int8le' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isneq(upc, ean13) + RETURNS boolean + AS 'int8eq' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnge(upc, ean13) + RETURNS boolean + AS 'int8ge' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isngt(upc, ean13) + RETURNS boolean + AS 'int8gt' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION isnne(upc, ean13) + RETURNS boolean + AS 'int8ne' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +-- +-- Now the operators: +-- + +-- +-- EAN13 operators: +-- +--------------------------------------------------- +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ean13, + RIGHTARG = ean13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ean13, + RIGHTARG = ean13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ean13, + RIGHTARG = ean13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ean13, + RIGHTARG = ean13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ean13, + RIGHTARG = ean13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ean13, + RIGHTARG = ean13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ean13, + RIGHTARG = isbn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ean13, + RIGHTARG = isbn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ean13, + RIGHTARG = isbn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ean13, + RIGHTARG = isbn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ean13, + RIGHTARG = isbn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ean13, + RIGHTARG = isbn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = isbn13, + RIGHTARG = ean13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = isbn13, + RIGHTARG = ean13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = isbn13, + RIGHTARG = ean13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = isbn13, + RIGHTARG = ean13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = isbn13, + RIGHTARG = ean13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = isbn13, + RIGHTARG = ean13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ean13, + RIGHTARG = ismn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ean13, + RIGHTARG = ismn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ean13, + RIGHTARG = ismn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ean13, + RIGHTARG = ismn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ean13, + RIGHTARG = ismn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ean13, + RIGHTARG = ismn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ismn13, + RIGHTARG = ean13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ismn13, + RIGHTARG = ean13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ismn13, + RIGHTARG = ean13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ismn13, + RIGHTARG = ean13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ismn13, + RIGHTARG = ean13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ismn13, + RIGHTARG = ean13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ean13, + RIGHTARG = issn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ean13, + RIGHTARG = issn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ean13, + RIGHTARG = issn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ean13, + RIGHTARG = issn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ean13, + RIGHTARG = issn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ean13, + RIGHTARG = issn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ean13, + RIGHTARG = isbn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ean13, + RIGHTARG = isbn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ean13, + RIGHTARG = isbn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ean13, + RIGHTARG = isbn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ean13, + RIGHTARG = isbn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ean13, + RIGHTARG = isbn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ean13, + RIGHTARG = ismn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ean13, + RIGHTARG = ismn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ean13, + RIGHTARG = ismn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ean13, + RIGHTARG = ismn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ean13, + RIGHTARG = ismn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ean13, + RIGHTARG = ismn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ean13, + RIGHTARG = issn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ean13, + RIGHTARG = issn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ean13, + RIGHTARG = issn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ean13, + RIGHTARG = issn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ean13, + RIGHTARG = issn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ean13, + RIGHTARG = issn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ean13, + RIGHTARG = upc, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ean13, + RIGHTARG = upc, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ean13, + RIGHTARG = upc, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ean13, + RIGHTARG = upc, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ean13, + RIGHTARG = upc, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ean13, + RIGHTARG = upc, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +-- +-- ISBN13 operators: +-- +--------------------------------------------------- +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = isbn13, + RIGHTARG = isbn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = isbn13, + RIGHTARG = isbn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = isbn13, + RIGHTARG = isbn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = isbn13, + RIGHTARG = isbn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = isbn13, + RIGHTARG = isbn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = isbn13, + RIGHTARG = isbn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = isbn13, + RIGHTARG = isbn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = isbn13, + RIGHTARG = isbn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = isbn13, + RIGHTARG = isbn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = isbn13, + RIGHTARG = isbn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = isbn13, + RIGHTARG = isbn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = isbn13, + RIGHTARG = isbn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +-- +-- ISBN operators: +-- +--------------------------------------------------- +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = isbn, + RIGHTARG = isbn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = isbn, + RIGHTARG = isbn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = isbn, + RIGHTARG = isbn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = isbn, + RIGHTARG = isbn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = isbn, + RIGHTARG = isbn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = isbn, + RIGHTARG = isbn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = isbn, + RIGHTARG = isbn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = isbn, + RIGHTARG = isbn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = isbn, + RIGHTARG = isbn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = isbn, + RIGHTARG = isbn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = isbn, + RIGHTARG = isbn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = isbn, + RIGHTARG = isbn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = isbn, + RIGHTARG = ean13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = isbn, + RIGHTARG = ean13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = isbn, + RIGHTARG = ean13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = isbn, + RIGHTARG = ean13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = isbn, + RIGHTARG = ean13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = isbn, + RIGHTARG = ean13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +-- +-- ISMN13 operators: +-- +--------------------------------------------------- +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ismn13, + RIGHTARG = ismn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ismn13, + RIGHTARG = ismn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ismn13, + RIGHTARG = ismn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ismn13, + RIGHTARG = ismn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ismn13, + RIGHTARG = ismn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ismn13, + RIGHTARG = ismn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ismn13, + RIGHTARG = ismn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ismn13, + RIGHTARG = ismn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ismn13, + RIGHTARG = ismn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ismn13, + RIGHTARG = ismn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ismn13, + RIGHTARG = ismn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ismn13, + RIGHTARG = ismn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +-- +-- ISMN operators: +-- +--------------------------------------------------- +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ismn, + RIGHTARG = ismn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ismn, + RIGHTARG = ismn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ismn, + RIGHTARG = ismn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ismn, + RIGHTARG = ismn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ismn, + RIGHTARG = ismn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ismn, + RIGHTARG = ismn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ismn, + RIGHTARG = ismn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ismn, + RIGHTARG = ismn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ismn, + RIGHTARG = ismn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ismn, + RIGHTARG = ismn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ismn, + RIGHTARG = ismn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ismn, + RIGHTARG = ismn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = ismn, + RIGHTARG = ean13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = ismn, + RIGHTARG = ean13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = ismn, + RIGHTARG = ean13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = ismn, + RIGHTARG = ean13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = ismn, + RIGHTARG = ean13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = ismn, + RIGHTARG = ean13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +-- +-- ISSN13 operators: +-- +--------------------------------------------------- +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = issn13, + RIGHTARG = issn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = issn13, + RIGHTARG = issn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = issn13, + RIGHTARG = issn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = issn13, + RIGHTARG = issn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = issn13, + RIGHTARG = issn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = issn13, + RIGHTARG = issn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = issn13, + RIGHTARG = issn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = issn13, + RIGHTARG = issn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = issn13, + RIGHTARG = issn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = issn13, + RIGHTARG = issn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = issn13, + RIGHTARG = issn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = issn13, + RIGHTARG = issn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = issn13, + RIGHTARG = ean13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = issn13, + RIGHTARG = ean13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = issn13, + RIGHTARG = ean13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = issn13, + RIGHTARG = ean13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = issn13, + RIGHTARG = ean13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = issn13, + RIGHTARG = ean13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +-- +-- ISSN operators: +-- +--------------------------------------------------- +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = issn, + RIGHTARG = issn, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = issn, + RIGHTARG = issn, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = issn, + RIGHTARG = issn, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = issn, + RIGHTARG = issn, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = issn, + RIGHTARG = issn, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = issn, + RIGHTARG = issn, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = issn, + RIGHTARG = issn13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = issn, + RIGHTARG = issn13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = issn, + RIGHTARG = issn13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = issn, + RIGHTARG = issn13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = issn, + RIGHTARG = issn13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = issn, + RIGHTARG = issn13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = issn, + RIGHTARG = ean13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = issn, + RIGHTARG = ean13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = issn, + RIGHTARG = ean13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = issn, + RIGHTARG = ean13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = issn, + RIGHTARG = ean13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = issn, + RIGHTARG = ean13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +-- +-- UPC operators: +-- +--------------------------------------------------- +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = upc, + RIGHTARG = upc, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = upc, + RIGHTARG = upc, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = upc, + RIGHTARG = upc, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = upc, + RIGHTARG = upc, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = upc, + RIGHTARG = upc, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = upc, + RIGHTARG = upc, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +CREATE OPERATOR < ( + PROCEDURE = isnlt, + LEFTARG = upc, + RIGHTARG = ean13, + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR <= ( + PROCEDURE = isnle, + LEFTARG = upc, + RIGHTARG = ean13, + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel); +CREATE OPERATOR = ( + PROCEDURE = isneq, + LEFTARG = upc, + RIGHTARG = ean13, + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel, + MERGES, + HASHES); +CREATE OPERATOR >= ( + PROCEDURE = isnge, + LEFTARG = upc, + RIGHTARG = ean13, + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR > ( + PROCEDURE = isngt, + LEFTARG = upc, + RIGHTARG = ean13, + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel ); +CREATE OPERATOR <> ( + PROCEDURE = isnne, + LEFTARG = upc, + RIGHTARG = ean13, + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = neqsel, + JOIN = neqjoinsel); + +-- +-- Operator families for the various operator classes: +-- +--------------------------------------------------- + +CREATE OPERATOR FAMILY isn_ops USING btree; +CREATE OPERATOR FAMILY isn_ops USING hash; + +-- +-- Operator classes: +-- +--------------------------------------------------- +-- EAN13: +CREATE FUNCTION btean13cmp(ean13, ean13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS ean13_ops DEFAULT + FOR TYPE ean13 USING btree FAMILY isn_ops AS + OPERATOR 1 <, + OPERATOR 2 <=, + OPERATOR 3 =, + OPERATOR 4 >=, + OPERATOR 5 >, + FUNCTION 1 btean13cmp(ean13, ean13); + +CREATE FUNCTION hashean13(ean13) + RETURNS int4 + AS 'hashint8' + LANGUAGE 'internal' IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS ean13_ops DEFAULT + FOR TYPE ean13 USING hash FAMILY isn_ops AS + OPERATOR 1 =, + FUNCTION 1 hashean13(ean13); + +-- EAN13 vs other types: +CREATE FUNCTION btean13cmp(ean13, isbn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btean13cmp(ean13, ismn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btean13cmp(ean13, issn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btean13cmp(ean13, isbn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btean13cmp(ean13, ismn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btean13cmp(ean13, issn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btean13cmp(ean13, upc) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +ALTER OPERATOR FAMILY isn_ops USING btree ADD + OPERATOR 1 < (ean13, isbn13), + OPERATOR 1 < (ean13, ismn13), + OPERATOR 1 < (ean13, issn13), + OPERATOR 1 < (ean13, isbn), + OPERATOR 1 < (ean13, ismn), + OPERATOR 1 < (ean13, issn), + OPERATOR 1 < (ean13, upc), + OPERATOR 2 <= (ean13, isbn13), + OPERATOR 2 <= (ean13, ismn13), + OPERATOR 2 <= (ean13, issn13), + OPERATOR 2 <= (ean13, isbn), + OPERATOR 2 <= (ean13, ismn), + OPERATOR 2 <= (ean13, issn), + OPERATOR 2 <= (ean13, upc), + OPERATOR 3 = (ean13, isbn13), + OPERATOR 3 = (ean13, ismn13), + OPERATOR 3 = (ean13, issn13), + OPERATOR 3 = (ean13, isbn), + OPERATOR 3 = (ean13, ismn), + OPERATOR 3 = (ean13, issn), + OPERATOR 3 = (ean13, upc), + OPERATOR 4 >= (ean13, isbn13), + OPERATOR 4 >= (ean13, ismn13), + OPERATOR 4 >= (ean13, issn13), + OPERATOR 4 >= (ean13, isbn), + OPERATOR 4 >= (ean13, ismn), + OPERATOR 4 >= (ean13, issn), + OPERATOR 4 >= (ean13, upc), + OPERATOR 5 > (ean13, isbn13), + OPERATOR 5 > (ean13, ismn13), + OPERATOR 5 > (ean13, issn13), + OPERATOR 5 > (ean13, isbn), + OPERATOR 5 > (ean13, ismn), + OPERATOR 5 > (ean13, issn), + OPERATOR 5 > (ean13, upc), + FUNCTION 1 btean13cmp(ean13, isbn13), + FUNCTION 1 btean13cmp(ean13, ismn13), + FUNCTION 1 btean13cmp(ean13, issn13), + FUNCTION 1 btean13cmp(ean13, isbn), + FUNCTION 1 btean13cmp(ean13, ismn), + FUNCTION 1 btean13cmp(ean13, issn), + FUNCTION 1 btean13cmp(ean13, upc); + +ALTER OPERATOR FAMILY isn_ops USING hash ADD + OPERATOR 1 = (ean13, isbn13), + OPERATOR 1 = (ean13, ismn13), + OPERATOR 1 = (ean13, issn13), + OPERATOR 1 = (ean13, isbn), + OPERATOR 1 = (ean13, ismn), + OPERATOR 1 = (ean13, issn), + OPERATOR 1 = (ean13, upc); + +--------------------------------------------------- +-- ISBN13: +CREATE FUNCTION btisbn13cmp(isbn13, isbn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS isbn13_ops DEFAULT + FOR TYPE isbn13 USING btree FAMILY isn_ops AS + OPERATOR 1 <, + OPERATOR 2 <=, + OPERATOR 3 =, + OPERATOR 4 >=, + OPERATOR 5 >, + FUNCTION 1 btisbn13cmp(isbn13, isbn13); + +CREATE FUNCTION hashisbn13(isbn13) + RETURNS int4 + AS 'hashint8' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS isbn13_ops DEFAULT + FOR TYPE isbn13 USING hash FAMILY isn_ops AS + OPERATOR 1 =, + FUNCTION 1 hashisbn13(isbn13); + +-- ISBN13 vs other types: +CREATE FUNCTION btisbn13cmp(isbn13, ean13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btisbn13cmp(isbn13, isbn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +ALTER OPERATOR FAMILY isn_ops USING btree ADD + OPERATOR 1 < (isbn13, ean13), + OPERATOR 1 < (isbn13, isbn), + OPERATOR 2 <= (isbn13, ean13), + OPERATOR 2 <= (isbn13, isbn), + OPERATOR 3 = (isbn13, ean13), + OPERATOR 3 = (isbn13, isbn), + OPERATOR 4 >= (isbn13, ean13), + OPERATOR 4 >= (isbn13, isbn), + OPERATOR 5 > (isbn13, ean13), + OPERATOR 5 > (isbn13, isbn), + FUNCTION 1 btisbn13cmp(isbn13, ean13), + FUNCTION 1 btisbn13cmp(isbn13, isbn); + +ALTER OPERATOR FAMILY isn_ops USING hash ADD + OPERATOR 1 = (isbn13, ean13), + OPERATOR 1 = (isbn13, isbn); + +--------------------------------------------------- +-- ISBN: +CREATE FUNCTION btisbncmp(isbn, isbn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS isbn_ops DEFAULT + FOR TYPE isbn USING btree FAMILY isn_ops AS + OPERATOR 1 <, + OPERATOR 2 <=, + OPERATOR 3 =, + OPERATOR 4 >=, + OPERATOR 5 >, + FUNCTION 1 btisbncmp(isbn, isbn); + +CREATE FUNCTION hashisbn(isbn) + RETURNS int4 + AS 'hashint8' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS isbn_ops DEFAULT + FOR TYPE isbn USING hash FAMILY isn_ops AS + OPERATOR 1 =, + FUNCTION 1 hashisbn(isbn); + +-- ISBN vs other types: +CREATE FUNCTION btisbncmp(isbn, ean13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btisbncmp(isbn, isbn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +ALTER OPERATOR FAMILY isn_ops USING btree ADD + OPERATOR 1 < (isbn, ean13), + OPERATOR 1 < (isbn, isbn13), + OPERATOR 2 <= (isbn, ean13), + OPERATOR 2 <= (isbn, isbn13), + OPERATOR 3 = (isbn, ean13), + OPERATOR 3 = (isbn, isbn13), + OPERATOR 4 >= (isbn, ean13), + OPERATOR 4 >= (isbn, isbn13), + OPERATOR 5 > (isbn, ean13), + OPERATOR 5 > (isbn, isbn13), + FUNCTION 1 btisbncmp(isbn, ean13), + FUNCTION 1 btisbncmp(isbn, isbn13); + +ALTER OPERATOR FAMILY isn_ops USING hash ADD + OPERATOR 1 = (isbn, ean13), + OPERATOR 1 = (isbn, isbn13); + +--------------------------------------------------- +-- ISMN13: +CREATE FUNCTION btismn13cmp(ismn13, ismn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS ismn13_ops DEFAULT + FOR TYPE ismn13 USING btree FAMILY isn_ops AS + OPERATOR 1 <, + OPERATOR 2 <=, + OPERATOR 3 =, + OPERATOR 4 >=, + OPERATOR 5 >, + FUNCTION 1 btismn13cmp(ismn13, ismn13); + +CREATE FUNCTION hashismn13(ismn13) + RETURNS int4 + AS 'hashint8' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS ismn13_ops DEFAULT + FOR TYPE ismn13 USING hash FAMILY isn_ops AS + OPERATOR 1 =, + FUNCTION 1 hashismn13(ismn13); + +-- ISMN13 vs other types: +CREATE FUNCTION btismn13cmp(ismn13, ean13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btismn13cmp(ismn13, ismn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +ALTER OPERATOR FAMILY isn_ops USING btree ADD + OPERATOR 1 < (ismn13, ean13), + OPERATOR 1 < (ismn13, ismn), + OPERATOR 2 <= (ismn13, ean13), + OPERATOR 2 <= (ismn13, ismn), + OPERATOR 3 = (ismn13, ean13), + OPERATOR 3 = (ismn13, ismn), + OPERATOR 4 >= (ismn13, ean13), + OPERATOR 4 >= (ismn13, ismn), + OPERATOR 5 > (ismn13, ean13), + OPERATOR 5 > (ismn13, ismn), + FUNCTION 1 btismn13cmp(ismn13, ean13), + FUNCTION 1 btismn13cmp(ismn13, ismn); + +ALTER OPERATOR FAMILY isn_ops USING hash ADD + OPERATOR 1 = (ismn13, ean13), + OPERATOR 1 = (ismn13, ismn); + +--------------------------------------------------- +-- ISMN: +CREATE FUNCTION btismncmp(ismn, ismn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS ismn_ops DEFAULT + FOR TYPE ismn USING btree FAMILY isn_ops AS + OPERATOR 1 <, + OPERATOR 2 <=, + OPERATOR 3 =, + OPERATOR 4 >=, + OPERATOR 5 >, + FUNCTION 1 btismncmp(ismn, ismn); + +CREATE FUNCTION hashismn(ismn) + RETURNS int4 + AS 'hashint8' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS ismn_ops DEFAULT + FOR TYPE ismn USING hash FAMILY isn_ops AS + OPERATOR 1 =, + FUNCTION 1 hashismn(ismn); + +-- ISMN vs other types: +CREATE FUNCTION btismncmp(ismn, ean13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btismncmp(ismn, ismn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +ALTER OPERATOR FAMILY isn_ops USING btree ADD + OPERATOR 1 < (ismn, ean13), + OPERATOR 1 < (ismn, ismn13), + OPERATOR 2 <= (ismn, ean13), + OPERATOR 2 <= (ismn, ismn13), + OPERATOR 3 = (ismn, ean13), + OPERATOR 3 = (ismn, ismn13), + OPERATOR 4 >= (ismn, ean13), + OPERATOR 4 >= (ismn, ismn13), + OPERATOR 5 > (ismn, ean13), + OPERATOR 5 > (ismn, ismn13), + FUNCTION 1 btismncmp(ismn, ean13), + FUNCTION 1 btismncmp(ismn, ismn13); + +ALTER OPERATOR FAMILY isn_ops USING hash ADD + OPERATOR 1 = (ismn, ean13), + OPERATOR 1 = (ismn, ismn13); + +--------------------------------------------------- +-- ISSN13: +CREATE FUNCTION btissn13cmp(issn13, issn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS issn13_ops DEFAULT + FOR TYPE issn13 USING btree FAMILY isn_ops AS + OPERATOR 1 <, + OPERATOR 2 <=, + OPERATOR 3 =, + OPERATOR 4 >=, + OPERATOR 5 >, + FUNCTION 1 btissn13cmp(issn13, issn13); + +CREATE FUNCTION hashissn13(issn13) + RETURNS int4 + AS 'hashint8' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS issn13_ops DEFAULT + FOR TYPE issn13 USING hash FAMILY isn_ops AS + OPERATOR 1 =, + FUNCTION 1 hashissn13(issn13); + +-- ISSN13 vs other types: +CREATE FUNCTION btissn13cmp(issn13, ean13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btissn13cmp(issn13, issn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +ALTER OPERATOR FAMILY isn_ops USING btree ADD + OPERATOR 1 < (issn13, ean13), + OPERATOR 1 < (issn13, issn), + OPERATOR 2 <= (issn13, ean13), + OPERATOR 2 <= (issn13, issn), + OPERATOR 3 = (issn13, ean13), + OPERATOR 3 = (issn13, issn), + OPERATOR 4 >= (issn13, ean13), + OPERATOR 4 >= (issn13, issn), + OPERATOR 5 > (issn13, ean13), + OPERATOR 5 > (issn13, issn), + FUNCTION 1 btissn13cmp(issn13, ean13), + FUNCTION 1 btissn13cmp(issn13, issn); + +ALTER OPERATOR FAMILY isn_ops USING hash ADD + OPERATOR 1 = (issn13, ean13), + OPERATOR 1 = (issn13, issn); + +--------------------------------------------------- +-- ISSN: +CREATE FUNCTION btissncmp(issn, issn) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS issn_ops DEFAULT + FOR TYPE issn USING btree FAMILY isn_ops AS + OPERATOR 1 <, + OPERATOR 2 <=, + OPERATOR 3 =, + OPERATOR 4 >=, + OPERATOR 5 >, + FUNCTION 1 btissncmp(issn, issn); + +CREATE FUNCTION hashissn(issn) + RETURNS int4 + AS 'hashint8' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS issn_ops DEFAULT + FOR TYPE issn USING hash FAMILY isn_ops AS + OPERATOR 1 =, + FUNCTION 1 hashissn(issn); + +-- ISSN vs other types: +CREATE FUNCTION btissncmp(issn, ean13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION btissncmp(issn, issn13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +ALTER OPERATOR FAMILY isn_ops USING btree ADD + OPERATOR 1 < (issn, ean13), + OPERATOR 1 < (issn, issn13), + OPERATOR 2 <= (issn, ean13), + OPERATOR 2 <= (issn, issn13), + OPERATOR 3 = (issn, ean13), + OPERATOR 3 = (issn, issn13), + OPERATOR 4 >= (issn, ean13), + OPERATOR 4 >= (issn, issn13), + OPERATOR 5 > (issn, ean13), + OPERATOR 5 > (issn, issn13), + FUNCTION 1 btissncmp(issn, ean13), + FUNCTION 1 btissncmp(issn, issn13); + +ALTER OPERATOR FAMILY isn_ops USING hash ADD + OPERATOR 1 = (issn, ean13), + OPERATOR 1 = (issn, issn13); + +--------------------------------------------------- +-- UPC: +CREATE FUNCTION btupccmp(upc, upc) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS upc_ops DEFAULT + FOR TYPE upc USING btree FAMILY isn_ops AS + OPERATOR 1 <, + OPERATOR 2 <=, + OPERATOR 3 =, + OPERATOR 4 >=, + OPERATOR 5 >, + FUNCTION 1 btupccmp(upc, upc); + +CREATE FUNCTION hashupc(upc) + RETURNS int4 + AS 'hashint8' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE OPERATOR CLASS upc_ops DEFAULT + FOR TYPE upc USING hash FAMILY isn_ops AS + OPERATOR 1 =, + FUNCTION 1 hashupc(upc); + +-- UPC vs other types: +CREATE FUNCTION btupccmp(upc, ean13) + RETURNS int4 + AS 'btint8cmp' + LANGUAGE 'internal' + IMMUTABLE STRICT + PARALLEL SAFE; + +ALTER OPERATOR FAMILY isn_ops USING btree ADD + OPERATOR 1 < (upc, ean13), + OPERATOR 2 <= (upc, ean13), + OPERATOR 3 = (upc, ean13), + OPERATOR 4 >= (upc, ean13), + OPERATOR 5 > (upc, ean13), + FUNCTION 1 btupccmp(upc, ean13); + +ALTER OPERATOR FAMILY isn_ops USING hash ADD + OPERATOR 1 = (upc, ean13); + +-- +-- Type casts: +-- +--------------------------------------------------- +CREATE FUNCTION isbn13(ean13) +RETURNS isbn13 +AS 'MODULE_PATHNAME', 'isbn_cast_from_ean13' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION ismn13(ean13) +RETURNS ismn13 +AS 'MODULE_PATHNAME', 'ismn_cast_from_ean13' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION issn13(ean13) +RETURNS issn13 +AS 'MODULE_PATHNAME', 'issn_cast_from_ean13' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION isbn(ean13) +RETURNS isbn +AS 'MODULE_PATHNAME', 'isbn_cast_from_ean13' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION ismn(ean13) +RETURNS ismn +AS 'MODULE_PATHNAME', 'ismn_cast_from_ean13' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION issn(ean13) +RETURNS issn +AS 'MODULE_PATHNAME', 'issn_cast_from_ean13' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION upc(ean13) +RETURNS upc +AS 'MODULE_PATHNAME', 'upc_cast_from_ean13' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + + +CREATE CAST (ean13 AS isbn13) WITH FUNCTION isbn13(ean13); +CREATE CAST (ean13 AS isbn) WITH FUNCTION isbn(ean13); +CREATE CAST (ean13 AS ismn13) WITH FUNCTION ismn13(ean13); +CREATE CAST (ean13 AS ismn) WITH FUNCTION ismn(ean13); +CREATE CAST (ean13 AS issn13) WITH FUNCTION issn13(ean13); +CREATE CAST (ean13 AS issn) WITH FUNCTION issn(ean13); +CREATE CAST (ean13 AS upc) WITH FUNCTION upc(ean13); + +CREATE CAST (isbn13 AS ean13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (isbn AS ean13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (ismn13 AS ean13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (ismn AS ean13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (issn13 AS ean13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (issn AS ean13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (upc AS ean13) WITHOUT FUNCTION AS ASSIGNMENT; + +CREATE CAST (isbn AS isbn13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (isbn13 AS isbn) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (ismn AS ismn13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (ismn13 AS ismn) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (issn AS issn13) WITHOUT FUNCTION AS ASSIGNMENT; +CREATE CAST (issn13 AS issn) WITHOUT FUNCTION AS ASSIGNMENT; + +-- +-- Validation stuff for lose types: +-- +CREATE FUNCTION make_valid(ean13) + RETURNS ean13 + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION make_valid(isbn13) + RETURNS isbn13 + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION make_valid(ismn13) + RETURNS ismn13 + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION make_valid(issn13) + RETURNS issn13 + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION make_valid(isbn) + RETURNS isbn + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION make_valid(ismn) + RETURNS ismn + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION make_valid(issn) + RETURNS issn + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION make_valid(upc) + RETURNS upc + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; + +CREATE FUNCTION is_valid(ean13) + RETURNS boolean + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION is_valid(isbn13) + RETURNS boolean + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION is_valid(ismn13) + RETURNS boolean + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION is_valid(issn13) + RETURNS boolean + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION is_valid(isbn) + RETURNS boolean + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION is_valid(ismn) + RETURNS boolean + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION is_valid(issn) + RETURNS boolean + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; +CREATE FUNCTION is_valid(upc) + RETURNS boolean + AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL SAFE; + +-- +-- isn_weak(boolean) - Sets the weak input mode. +-- This function is intended for testing use only! +-- +CREATE FUNCTION isn_weak(boolean) + RETURNS boolean + AS 'MODULE_PATHNAME', 'accept_weak_input' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL RESTRICTED; + +-- +-- isn_weak() - Gets the weak input mode status +-- +CREATE FUNCTION isn_weak() + RETURNS boolean + AS 'MODULE_PATHNAME', 'weak_input_status' + LANGUAGE C + IMMUTABLE STRICT + PARALLEL RESTRICTED; diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c new file mode 100644 index 0000000..7493a2c --- /dev/null +++ b/contrib/isn/isn.c @@ -0,0 +1,1139 @@ +/*------------------------------------------------------------------------- + * + * isn.c + * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) + * + * Author: German Mendez Bravo (Kronuz) + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * + * IDENTIFICATION + * contrib/isn/isn.c + * + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "EAN13.h" +#include "ISBN.h" +#include "ISMN.h" +#include "ISSN.h" +#include "UPC.h" +#include "fmgr.h" +#include "isn.h" +#include "utils/builtins.h" + +PG_MODULE_MAGIC; + +#ifdef USE_ASSERT_CHECKING +#define ISN_DEBUG 1 +#else +#define ISN_DEBUG 0 +#endif + +#define MAXEAN13LEN 18 + +enum isn_type +{ + INVALID, ANY, EAN13, ISBN, ISMN, ISSN, UPC +}; + +static const char *const isn_names[] = {"EAN13/UPC/ISxN", "EAN13/UPC/ISxN", "EAN13", "ISBN", "ISMN", "ISSN", "UPC"}; + +static bool g_weak = false; + + +/*********************************************************************** + ** + ** Routines for EAN13/UPC/ISxNs. + ** + ** Note: + ** In this code, a normalized string is one that is known to be a valid + ** ISxN number containing only digits and hyphens and with enough space + ** to hold the full 13 digits plus the maximum of four hyphens. + ***********************************************************************/ + +/*---------------------------------------------------------- + * Debugging routines. + *---------------------------------------------------------*/ + +/* + * Check if the table and its index is correct (just for debugging) + */ +pg_attribute_unused() +static bool +check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2]) +{ + const char *aux1, + *aux2; + int a, + b, + x = 0, + y = -1, + i = 0, + j, + init = 0; + + if (TABLE == NULL || TABLE_index == NULL) + return true; + + while (TABLE[i][0] && TABLE[i][1]) + { + aux1 = TABLE[i][0]; + aux2 = TABLE[i][1]; + + /* must always start with a digit: */ + if (!isdigit((unsigned char) *aux1) || !isdigit((unsigned char) *aux2)) + goto invalidtable; + a = *aux1 - '0'; + b = *aux2 - '0'; + + /* must always have the same format and length: */ + while (*aux1 && *aux2) + { + if (!(isdigit((unsigned char) *aux1) && + isdigit((unsigned char) *aux2)) && + (*aux1 != *aux2 || *aux1 != '-')) + goto invalidtable; + aux1++; + aux2++; + } + if (*aux1 != *aux2) + goto invalidtable; + + /* found a new range */ + if (a > y) + { + /* check current range in the index: */ + for (j = x; j <= y; j++) + { + if (TABLE_index[j][0] != init) + goto invalidindex; + if (TABLE_index[j][1] != i - init) + goto invalidindex; + } + init = i; + x = a; + } + + /* Always get the new limit */ + y = b; + if (y < x) + goto invalidtable; + i++; + } + + return true; + +invalidtable: + elog(DEBUG1, "invalid table near {\"%s\", \"%s\"} (pos: %d)", + TABLE[i][0], TABLE[i][1], i); + return false; + +invalidindex: + elog(DEBUG1, "index %d is invalid", j); + return false; +} + +/*---------------------------------------------------------- + * Formatting and conversion routines. + *---------------------------------------------------------*/ + +static unsigned +dehyphenate(char *bufO, char *bufI) +{ + unsigned ret = 0; + + while (*bufI) + { + if (isdigit((unsigned char) *bufI)) + { + *bufO++ = *bufI; + ret++; + } + bufI++; + } + *bufO = '\0'; + return ret; +} + +/* + * hyphenate --- Try to hyphenate, in-place, the string starting at bufI + * into bufO using the given hyphenation range TABLE. + * Assumes the input string to be used is of only digits. + * + * Returns the number of characters actually hyphenated. + */ +static unsigned +hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsigned TABLE_index[10][2]) +{ + unsigned ret = 0; + const char *ean_aux1, + *ean_aux2, + *ean_p; + char *firstdig, + *aux1, + *aux2; + unsigned search, + upper, + lower, + step; + bool ean_in1, + ean_in2; + + /* just compress the string if no further hyphenation is required */ + if (TABLE == NULL || TABLE_index == NULL) + { + while (*bufI) + { + *bufO++ = *bufI++; + ret++; + } + *bufO = '\0'; + return (ret + 1); + } + + /* add remaining hyphenations */ + + search = *bufI - '0'; + upper = lower = TABLE_index[search][0]; + upper += TABLE_index[search][1]; + lower--; + + step = (upper - lower) / 2; + if (step == 0) + return 0; + search = lower + step; + + firstdig = bufI; + ean_in1 = ean_in2 = false; + ean_aux1 = TABLE[search][0]; + ean_aux2 = TABLE[search][1]; + do + { + if ((ean_in1 || *firstdig >= *ean_aux1) && (ean_in2 || *firstdig <= *ean_aux2)) + { + if (*firstdig > *ean_aux1) + ean_in1 = true; + if (*firstdig < *ean_aux2) + ean_in2 = true; + if (ean_in1 && ean_in2) + break; + + firstdig++, ean_aux1++, ean_aux2++; + if (!(*ean_aux1 && *ean_aux2 && *firstdig)) + break; + if (!isdigit((unsigned char) *ean_aux1)) + ean_aux1++, ean_aux2++; + } + else + { + /* + * check in what direction we should go and move the pointer + * accordingly + */ + if (*firstdig < *ean_aux1 && !ean_in1) + upper = search; + else + lower = search; + + step = (upper - lower) / 2; + search = lower + step; + + /* Initialize stuff again: */ + firstdig = bufI; + ean_in1 = ean_in2 = false; + ean_aux1 = TABLE[search][0]; + ean_aux2 = TABLE[search][1]; + } + } while (step); + + if (step) + { + aux1 = bufO; + aux2 = bufI; + ean_p = TABLE[search][0]; + while (*ean_p && *aux2) + { + if (*ean_p++ != '-') + *aux1++ = *aux2++; + else + *aux1++ = '-'; + ret++; + } + *aux1++ = '-'; + *aux1 = *aux2; /* add a lookahead char */ + return (ret + 1); + } + return ret; +} + +/* + * weight_checkdig -- Receives a buffer with a normalized ISxN string number, + * and the length to weight. + * + * Returns the weight of the number (the check digit value, 0-10) + */ +static unsigned +weight_checkdig(char *isn, unsigned size) +{ + unsigned weight = 0; + + while (*isn && size > 1) + { + if (isdigit((unsigned char) *isn)) + { + weight += size-- * (*isn - '0'); + } + isn++; + } + weight = weight % 11; + if (weight != 0) + weight = 11 - weight; + return weight; +} + + +/* + * checkdig --- Receives a buffer with a normalized ISxN string number, + * and the length to check. + * + * Returns the check digit value (0-9) + */ +static unsigned +checkdig(char *num, unsigned size) +{ + unsigned check = 0, + check3 = 0; + unsigned pos = 0; + + if (*num == 'M') + { /* ISMN start with 'M' */ + check3 = 3; + pos = 1; + } + while (*num && size > 1) + { + if (isdigit((unsigned char) *num)) + { + if (pos++ % 2) + check3 += *num - '0'; + else + check += *num - '0'; + size--; + } + num++; + } + check = (check + 3 * check3) % 10; + if (check != 0) + check = 10 - check; + return check; +} + +/* + * ean2isn --- Try to convert an ean13 number to a UPC/ISxN number. + * This doesn't verify for a valid check digit. + * + * If errorOK is false, ereport a useful error message if the ean13 is bad. + * If errorOK is true, just return "false" for bad input. + */ +static bool +ean2isn(ean13 ean, bool errorOK, ean13 *result, enum isn_type accept) +{ + enum isn_type type = INVALID; + + char buf[MAXEAN13LEN + 1]; + char *aux; + unsigned digval; + unsigned search; + ean13 ret = ean; + + ean >>= 1; + /* verify it's in the EAN13 range */ + if (ean > UINT64CONST(9999999999999)) + goto eantoobig; + + /* convert the number */ + search = 0; + aux = buf + 13; + *aux = '\0'; /* terminate string; aux points to last digit */ + do + { + digval = (unsigned) (ean % 10); /* get the decimal value */ + ean /= 10; /* get next digit */ + *--aux = (char) (digval + '0'); /* convert to ascii and store */ + } while (ean && search++ < 12); + while (search++ < 12) + *--aux = '0'; /* fill the remaining EAN13 with '0' */ + + /* find out the data type: */ + if (strncmp("978", buf, 3) == 0) + { /* ISBN */ + type = ISBN; + } + else if (strncmp("977", buf, 3) == 0) + { /* ISSN */ + type = ISSN; + } + else if (strncmp("9790", buf, 4) == 0) + { /* ISMN */ + type = ISMN; + } + else if (strncmp("979", buf, 3) == 0) + { /* ISBN-13 */ + type = ISBN; + } + else if (*buf == '0') + { /* UPC */ + type = UPC; + } + else + { + type = EAN13; + } + if (accept != ANY && accept != EAN13 && accept != type) + goto eanwrongtype; + + *result = ret; + return true; + +eanwrongtype: + if (!errorOK) + { + if (type != EAN13) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("cannot cast EAN13(%s) to %s for number: \"%s\"", + isn_names[type], isn_names[accept], buf))); + } + else + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("cannot cast %s to %s for number: \"%s\"", + isn_names[type], isn_names[accept], buf))); + } + } + return false; + +eantoobig: + if (!errorOK) + { + char eanbuf[64]; + + /* + * Format the number separately to keep the machine-dependent format + * code out of the translatable message text + */ + snprintf(eanbuf, sizeof(eanbuf), EAN13_FORMAT, ean); + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("value \"%s\" is out of range for %s type", + eanbuf, isn_names[type]))); + } + return false; +} + +/* + * ean2UPC/ISxN --- Convert in-place a normalized EAN13 string to the corresponding + * UPC/ISxN string number. Assumes the input string is normalized. + */ +static inline void +ean2ISBN(char *isn) +{ + char *aux; + unsigned check; + + /* + * The number should come in this format: 978-0-000-00000-0 or may be an + * ISBN-13 number, 979-..., which does not have a short representation. Do + * the short output version if possible. + */ + if (strncmp("978-", isn, 4) == 0) + { + /* Strip the first part and calculate the new check digit */ + hyphenate(isn, isn + 4, NULL, NULL); + check = weight_checkdig(isn, 10); + aux = strchr(isn, '\0'); + while (!isdigit((unsigned char) *--aux)); + if (check == 10) + *aux = 'X'; + else + *aux = check + '0'; + } +} + +static inline void +ean2ISMN(char *isn) +{ + /* the number should come in this format: 979-0-000-00000-0 */ + /* Just strip the first part and change the first digit ('0') to 'M' */ + hyphenate(isn, isn + 4, NULL, NULL); + isn[0] = 'M'; +} + +static inline void +ean2ISSN(char *isn) +{ + unsigned check; + + /* the number should come in this format: 977-0000-000-00-0 */ + /* Strip the first part, crop, and calculate the new check digit */ + hyphenate(isn, isn + 4, NULL, NULL); + check = weight_checkdig(isn, 8); + if (check == 10) + isn[8] = 'X'; + else + isn[8] = check + '0'; + isn[9] = '\0'; +} + +static inline void +ean2UPC(char *isn) +{ + /* the number should come in this format: 000-000000000-0 */ + /* Strip the first part, crop, and dehyphenate */ + dehyphenate(isn, isn + 1); + isn[12] = '\0'; +} + +/* + * ean2* --- Converts a string of digits into an ean13 number. + * Assumes the input string is a string with only digits + * on it, and that it's within the range of ean13. + * + * Returns the ean13 value of the string. + */ +static ean13 +str2ean(const char *num) +{ + ean13 ean = 0; /* current ean */ + + while (*num) + { + if (isdigit((unsigned char) *num)) + ean = 10 * ean + (*num - '0'); + num++; + } + return (ean << 1); /* also give room to a flag */ +} + +/* + * ean2string --- Try to convert an ean13 number to a hyphenated string. + * Assumes there's enough space in result to hold + * the string (maximum MAXEAN13LEN+1 bytes) + * This doesn't verify for a valid check digit. + * + * If shortType is true, the returned string is in the old ISxN short format. + * If errorOK is false, ereport a useful error message if the string is bad. + * If errorOK is true, just return "false" for bad input. + */ +static bool +ean2string(ean13 ean, bool errorOK, char *result, bool shortType) +{ + const char *(*TABLE)[2]; + const unsigned (*TABLE_index)[2]; + enum isn_type type = INVALID; + + char *aux; + unsigned digval; + unsigned search; + char valid = '\0'; /* was the number initially written with a + * valid check digit? */ + + TABLE_index = ISBN_index; + + if ((ean & 1) != 0) + valid = '!'; + ean >>= 1; + /* verify it's in the EAN13 range */ + if (ean > UINT64CONST(9999999999999)) + goto eantoobig; + + /* convert the number */ + search = 0; + aux = result + MAXEAN13LEN; + *aux = '\0'; /* terminate string; aux points to last digit */ + *--aux = valid; /* append '!' for numbers with invalid but + * corrected check digit */ + do + { + digval = (unsigned) (ean % 10); /* get the decimal value */ + ean /= 10; /* get next digit */ + *--aux = (char) (digval + '0'); /* convert to ascii and store */ + if (search == 0) + *--aux = '-'; /* the check digit is always there */ + } while (ean && search++ < 13); + while (search++ < 13) + *--aux = '0'; /* fill the remaining EAN13 with '0' */ + + /* The string should be in this form: ???DDDDDDDDDDDD-D" */ + search = hyphenate(result, result + 3, EAN13_range, EAN13_index); + + /* verify it's a logically valid EAN13 */ + if (search == 0) + { + search = hyphenate(result, result + 3, NULL, NULL); + goto okay; + } + + /* find out what type of hyphenation is needed: */ + if (strncmp("978-", result, search) == 0) + { /* ISBN -13 978-range */ + /* The string should be in this form: 978-??000000000-0" */ + type = ISBN; + TABLE = ISBN_range; + TABLE_index = ISBN_index; + } + else if (strncmp("977-", result, search) == 0) + { /* ISSN */ + /* The string should be in this form: 977-??000000000-0" */ + type = ISSN; + TABLE = ISSN_range; + TABLE_index = ISSN_index; + } + else if (strncmp("979-0", result, search + 1) == 0) + { /* ISMN */ + /* The string should be in this form: 979-0?000000000-0" */ + type = ISMN; + TABLE = ISMN_range; + TABLE_index = ISMN_index; + } + else if (strncmp("979-", result, search) == 0) + { /* ISBN-13 979-range */ + /* The string should be in this form: 979-??000000000-0" */ + type = ISBN; + TABLE = ISBN_range_new; + TABLE_index = ISBN_index_new; + } + else if (*result == '0') + { /* UPC */ + /* The string should be in this form: 000-00000000000-0" */ + type = UPC; + TABLE = UPC_range; + TABLE_index = UPC_index; + } + else + { + type = EAN13; + TABLE = NULL; + TABLE_index = NULL; + } + + /* verify it's a logically valid EAN13/UPC/ISxN */ + digval = search; + search = hyphenate(result + digval, result + digval + 2, TABLE, TABLE_index); + + /* verify it's a valid EAN13 */ + if (search == 0) + { + search = hyphenate(result + digval, result + digval + 2, NULL, NULL); + goto okay; + } + +okay: + /* convert to the old short type: */ + if (shortType) + switch (type) + { + case ISBN: + ean2ISBN(result); + break; + case ISMN: + ean2ISMN(result); + break; + case ISSN: + ean2ISSN(result); + break; + case UPC: + ean2UPC(result); + break; + default: + break; + } + return true; + +eantoobig: + if (!errorOK) + { + char eanbuf[64]; + + /* + * Format the number separately to keep the machine-dependent format + * code out of the translatable message text + */ + snprintf(eanbuf, sizeof(eanbuf), EAN13_FORMAT, ean); + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("value \"%s\" is out of range for %s type", + eanbuf, isn_names[type]))); + } + return false; +} + +/* + * string2ean --- try to parse a string into an ean13. + * + * If errorOK is false, ereport a useful error message if the string is bad. + * If errorOK is true, just return "false" for bad input. + * + * if the input string ends with '!' it will always be treated as invalid + * (even if the check digit is valid) + */ +static bool +string2ean(const char *str, bool errorOK, ean13 *result, + enum isn_type accept) +{ + bool digit, + last; + char buf[17] = " "; + char *aux1 = buf + 3; /* leave space for the first part, in case + * it's needed */ + const char *aux2 = str; + enum isn_type type = INVALID; + unsigned check = 0, + rcheck = (unsigned) -1; + unsigned length = 0; + bool magic = false, + valid = true; + + /* recognize and validate the number: */ + while (*aux2 && length <= 13) + { + last = (*(aux2 + 1) == '!' || *(aux2 + 1) == '\0'); /* is the last character */ + digit = (isdigit((unsigned char) *aux2) != 0); /* is current character + * a digit? */ + if (*aux2 == '?' && last) /* automagically calculate check digit if + * it's '?' */ + magic = digit = true; + if (length == 0 && (*aux2 == 'M' || *aux2 == 'm')) + { + /* only ISMN can be here */ + if (type != INVALID) + goto eaninvalid; + type = ISMN; + *aux1++ = 'M'; + length++; + } + else if (length == 7 && (digit || *aux2 == 'X' || *aux2 == 'x') && last) + { + /* only ISSN can be here */ + if (type != INVALID) + goto eaninvalid; + type = ISSN; + *aux1++ = toupper((unsigned char) *aux2); + length++; + } + else if (length == 9 && (digit || *aux2 == 'X' || *aux2 == 'x') && last) + { + /* only ISBN and ISMN can be here */ + if (type != INVALID && type != ISMN) + goto eaninvalid; + if (type == INVALID) + type = ISBN; /* ISMN must start with 'M' */ + *aux1++ = toupper((unsigned char) *aux2); + length++; + } + else if (length == 11 && digit && last) + { + /* only UPC can be here */ + if (type != INVALID) + goto eaninvalid; + type = UPC; + *aux1++ = *aux2; + length++; + } + else if (*aux2 == '-' || *aux2 == ' ') + { + /* skip, we could validate but I think it's worthless */ + } + else if (*aux2 == '!' && *(aux2 + 1) == '\0') + { + /* the invalid check digit suffix was found, set it */ + if (!magic) + valid = false; + magic = true; + } + else if (!digit) + { + goto eaninvalid; + } + else + { + *aux1++ = *aux2; + if (++length > 13) + goto eantoobig; + } + aux2++; + } + *aux1 = '\0'; /* terminate the string */ + + /* find the current check digit value */ + if (length == 13) + { + /* only EAN13 can be here */ + if (type != INVALID) + goto eaninvalid; + type = EAN13; + check = buf[15] - '0'; + } + else if (length == 12) + { + /* only UPC can be here */ + if (type != UPC) + goto eaninvalid; + check = buf[14] - '0'; + } + else if (length == 10) + { + if (type != ISBN && type != ISMN) + goto eaninvalid; + if (buf[12] == 'X') + check = 10; + else + check = buf[12] - '0'; + } + else if (length == 8) + { + if (type != INVALID && type != ISSN) + goto eaninvalid; + type = ISSN; + if (buf[10] == 'X') + check = 10; + else + check = buf[10] - '0'; + } + else + goto eaninvalid; + + if (type == INVALID) + goto eaninvalid; + + /* obtain the real check digit value, validate, and convert to ean13: */ + if (accept == EAN13 && type != accept) + goto eanwrongtype; + if (accept != ANY && type != EAN13 && type != accept) + goto eanwrongtype; + switch (type) + { + case EAN13: + valid = (valid && ((rcheck = checkdig(buf + 3, 13)) == check || magic)); + /* now get the subtype of EAN13: */ + if (buf[3] == '0') + type = UPC; + else if (strncmp("977", buf + 3, 3) == 0) + type = ISSN; + else if (strncmp("978", buf + 3, 3) == 0) + type = ISBN; + else if (strncmp("9790", buf + 3, 4) == 0) + type = ISMN; + else if (strncmp("979", buf + 3, 3) == 0) + type = ISBN; + if (accept != EAN13 && accept != ANY && type != accept) + goto eanwrongtype; + break; + case ISMN: + memcpy(buf, "9790", 4); /* this isn't for sure yet, for now ISMN + * it's only 9790 */ + valid = (valid && ((rcheck = checkdig(buf, 13)) == check || magic)); + break; + case ISBN: + memcpy(buf, "978", 3); + valid = (valid && ((rcheck = weight_checkdig(buf + 3, 10)) == check || magic)); + break; + case ISSN: + memcpy(buf + 10, "00", 2); /* append 00 as the normal issue + * publication code */ + memcpy(buf, "977", 3); + valid = (valid && ((rcheck = weight_checkdig(buf + 3, 8)) == check || magic)); + break; + case UPC: + buf[2] = '0'; + valid = (valid && ((rcheck = checkdig(buf + 2, 13)) == check || magic)); + default: + break; + } + + /* fix the check digit: */ + for (aux1 = buf; *aux1 && *aux1 <= ' '; aux1++); + aux1[12] = checkdig(aux1, 13) + '0'; + aux1[13] = '\0'; + + if (!valid && !magic) + goto eanbadcheck; + + *result = str2ean(aux1); + *result |= valid ? 0 : 1; + return true; + +eanbadcheck: + if (g_weak) + { /* weak input mode is activated: */ + /* set the "invalid-check-digit-on-input" flag */ + *result = str2ean(aux1); + *result |= 1; + return true; + } + + if (!errorOK) + { + if (rcheck == (unsigned) -1) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid %s number: \"%s\"", + isn_names[accept], str))); + } + else + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid check digit for %s number: \"%s\", should be %c", + isn_names[accept], str, (rcheck == 10) ? ('X') : (rcheck + '0')))); + } + } + return false; + +eaninvalid: + if (!errorOK) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid input syntax for %s number: \"%s\"", + isn_names[accept], str))); + return false; + +eanwrongtype: + if (!errorOK) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("cannot cast %s to %s for number: \"%s\"", + isn_names[type], isn_names[accept], str))); + return false; + +eantoobig: + if (!errorOK) + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("value \"%s\" is out of range for %s type", + str, isn_names[accept]))); + return false; +} + +/*---------------------------------------------------------- + * Exported routines. + *---------------------------------------------------------*/ + +void _PG_init(void); + +void +_PG_init(void) +{ + if (ISN_DEBUG) + { + if (!check_table(EAN13_range, EAN13_index)) + elog(ERROR, "EAN13 failed check"); + if (!check_table(ISBN_range, ISBN_index)) + elog(ERROR, "ISBN failed check"); + if (!check_table(ISMN_range, ISMN_index)) + elog(ERROR, "ISMN failed check"); + if (!check_table(ISSN_range, ISSN_index)) + elog(ERROR, "ISSN failed check"); + if (!check_table(UPC_range, UPC_index)) + elog(ERROR, "UPC failed check"); + } +} + +/* isn_out + */ +PG_FUNCTION_INFO_V1(isn_out); +Datum +isn_out(PG_FUNCTION_ARGS) +{ + ean13 val = PG_GETARG_EAN13(0); + char *result; + char buf[MAXEAN13LEN + 1]; + + (void) ean2string(val, false, buf, true); + + result = pstrdup(buf); + PG_RETURN_CSTRING(result); +} + +/* ean13_out + */ +PG_FUNCTION_INFO_V1(ean13_out); +Datum +ean13_out(PG_FUNCTION_ARGS) +{ + ean13 val = PG_GETARG_EAN13(0); + char *result; + char buf[MAXEAN13LEN + 1]; + + (void) ean2string(val, false, buf, false); + + result = pstrdup(buf); + PG_RETURN_CSTRING(result); +} + +/* ean13_in + */ +PG_FUNCTION_INFO_V1(ean13_in); +Datum +ean13_in(PG_FUNCTION_ARGS) +{ + const char *str = PG_GETARG_CSTRING(0); + ean13 result; + + (void) string2ean(str, false, &result, EAN13); + PG_RETURN_EAN13(result); +} + +/* isbn_in + */ +PG_FUNCTION_INFO_V1(isbn_in); +Datum +isbn_in(PG_FUNCTION_ARGS) +{ + const char *str = PG_GETARG_CSTRING(0); + ean13 result; + + (void) string2ean(str, false, &result, ISBN); + PG_RETURN_EAN13(result); +} + +/* ismn_in + */ +PG_FUNCTION_INFO_V1(ismn_in); +Datum +ismn_in(PG_FUNCTION_ARGS) +{ + const char *str = PG_GETARG_CSTRING(0); + ean13 result; + + (void) string2ean(str, false, &result, ISMN); + PG_RETURN_EAN13(result); +} + +/* issn_in + */ +PG_FUNCTION_INFO_V1(issn_in); +Datum +issn_in(PG_FUNCTION_ARGS) +{ + const char *str = PG_GETARG_CSTRING(0); + ean13 result; + + (void) string2ean(str, false, &result, ISSN); + PG_RETURN_EAN13(result); +} + +/* upc_in + */ +PG_FUNCTION_INFO_V1(upc_in); +Datum +upc_in(PG_FUNCTION_ARGS) +{ + const char *str = PG_GETARG_CSTRING(0); + ean13 result; + + (void) string2ean(str, false, &result, UPC); + PG_RETURN_EAN13(result); +} + +/* casting functions +*/ +PG_FUNCTION_INFO_V1(isbn_cast_from_ean13); +Datum +isbn_cast_from_ean13(PG_FUNCTION_ARGS) +{ + ean13 val = PG_GETARG_EAN13(0); + ean13 result; + + (void) ean2isn(val, false, &result, ISBN); + + PG_RETURN_EAN13(result); +} + +PG_FUNCTION_INFO_V1(ismn_cast_from_ean13); +Datum +ismn_cast_from_ean13(PG_FUNCTION_ARGS) +{ + ean13 val = PG_GETARG_EAN13(0); + ean13 result; + + (void) ean2isn(val, false, &result, ISMN); + + PG_RETURN_EAN13(result); +} + +PG_FUNCTION_INFO_V1(issn_cast_from_ean13); +Datum +issn_cast_from_ean13(PG_FUNCTION_ARGS) +{ + ean13 val = PG_GETARG_EAN13(0); + ean13 result; + + (void) ean2isn(val, false, &result, ISSN); + + PG_RETURN_EAN13(result); +} + +PG_FUNCTION_INFO_V1(upc_cast_from_ean13); +Datum +upc_cast_from_ean13(PG_FUNCTION_ARGS) +{ + ean13 val = PG_GETARG_EAN13(0); + ean13 result; + + (void) ean2isn(val, false, &result, UPC); + + PG_RETURN_EAN13(result); +} + + +/* is_valid - returns false if the "invalid-check-digit-on-input" is set + */ +PG_FUNCTION_INFO_V1(is_valid); +Datum +is_valid(PG_FUNCTION_ARGS) +{ + ean13 val = PG_GETARG_EAN13(0); + + PG_RETURN_BOOL((val & 1) == 0); +} + +/* make_valid - unsets the "invalid-check-digit-on-input" flag + */ +PG_FUNCTION_INFO_V1(make_valid); +Datum +make_valid(PG_FUNCTION_ARGS) +{ + ean13 val = PG_GETARG_EAN13(0); + + val &= ~((ean13) 1); + PG_RETURN_EAN13(val); +} + +/* this function temporarily sets weak input flag + * (to lose the strictness of check digit acceptance) + * It's a helper function, not intended to be used!! + */ +PG_FUNCTION_INFO_V1(accept_weak_input); +Datum +accept_weak_input(PG_FUNCTION_ARGS) +{ +#ifdef ISN_WEAK_MODE + g_weak = PG_GETARG_BOOL(0); +#else + /* function has no effect */ +#endif /* ISN_WEAK_MODE */ + PG_RETURN_BOOL(g_weak); +} + +PG_FUNCTION_INFO_V1(weak_input_status); +Datum +weak_input_status(PG_FUNCTION_ARGS) +{ + PG_RETURN_BOOL(g_weak); +} diff --git a/contrib/isn/isn.control b/contrib/isn/isn.control new file mode 100644 index 0000000..1cb5e2b --- /dev/null +++ b/contrib/isn/isn.control @@ -0,0 +1,6 @@ +# isn extension +comment = 'data types for international product numbering standards' +default_version = '1.2' +module_pathname = '$libdir/isn' +relocatable = true +trusted = true diff --git a/contrib/isn/isn.h b/contrib/isn/isn.h new file mode 100644 index 0000000..e78caff --- /dev/null +++ b/contrib/isn/isn.h @@ -0,0 +1,35 @@ +/*------------------------------------------------------------------------- + * + * isn.h + * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) + * + * Author: German Mendez Bravo (Kronuz) + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * + * IDENTIFICATION + * contrib/isn/isn.h + * + *------------------------------------------------------------------------- + */ + +#ifndef ISN_H +#define ISN_H + +#include "fmgr.h" + +#undef ISN_DEBUG +#define ISN_WEAK_MODE + +/* + * uint64 is the internal storage format for ISNs. + */ +typedef uint64 ean13; + +#define EAN13_FORMAT UINT64_FORMAT + +#define PG_GETARG_EAN13(n) PG_GETARG_INT64(n) +#define PG_RETURN_EAN13(x) PG_RETURN_INT64(x) + +extern void initialize(void); + +#endif /* ISN_H */ diff --git a/contrib/isn/sql/isn.sql b/contrib/isn/sql/isn.sql new file mode 100644 index 0000000..71577d5 --- /dev/null +++ b/contrib/isn/sql/isn.sql @@ -0,0 +1,113 @@ +-- +-- Test ISN extension +-- + +CREATE EXTENSION isn; + +-- Check whether any of our opclasses fail amvalidate +-- ... they will, because of missing cross-type operators +SELECT amname, opcname +FROM (SELECT amname, opcname, opc.oid + FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod + WHERE opc.oid >= 16384 + ORDER BY 1, 2 OFFSET 0) ss +WHERE NOT amvalidate(oid); + +-- +-- test valid conversions +-- +SELECT '9780123456786'::EAN13, -- old book + '9790123456785'::EAN13, -- music + '9791234567896'::EAN13, -- new book + '9771234567898'::EAN13, -- serial + '0123456789012'::EAN13, -- upc + '1234567890128'::EAN13; + +SELECT '9780123456786'::ISBN, + '123456789X'::ISBN, + '9780123456786'::ISBN13::ISBN, + '9780123456786'::EAN13::ISBN; + +SELECT -- new books, shown as ISBN13 even for ISBN... + '9791234567896'::ISBN, + '9791234567896'::ISBN13::ISBN, + '9791234567896'::EAN13::ISBN; + +SELECT '9780123456786'::ISBN13, + '123456789X'::ISBN13, + '9791234567896'::ISBN13, + '9791234567896'::EAN13::ISBN13; + +SELECT '9790123456785'::ISMN, + '9790123456785'::EAN13::ISMN, + 'M123456785'::ISMN, + 'M-1234-5678-5'::ISMN; + +SELECT '9790123456785'::ISMN13, + 'M123456785'::ISMN13, + 'M-1234-5678-5'::ISMN13; + +SELECT '9771234567003'::ISSN, + '12345679'::ISSN; + +SELECT '9771234567003'::ISSN13, + '12345679'::ISSN13, + '9771234567898'::ISSN13, + '9771234567898'::EAN13::ISSN13; + +SELECT '0123456789012'::UPC, + '0123456789012'::EAN13::UPC; + +-- +-- test invalid checksums +-- +SELECT '1234567890'::ISBN; +SELECT 'M123456780'::ISMN; +SELECT '12345670'::ISSN; +SELECT '9780123456780'::ISBN; +SELECT '9791234567890'::ISBN13; +SELECT '0123456789010'::UPC; +SELECT '1234567890120'::EAN13; + +-- +-- test invalid conversions +-- +SELECT '9790123456785'::ISBN; -- not a book +SELECT '9771234567898'::ISBN; -- not a book +SELECT '0123456789012'::ISBN; -- not a book + +SELECT '9790123456785'::ISBN13; -- not a book +SELECT '9771234567898'::ISBN13; -- not a book +SELECT '0123456789012'::ISBN13; -- not a book + +SELECT '9780123456786'::ISMN; -- not music +SELECT '9771234567898'::ISMN; -- not music +SELECT '9791234567896'::ISMN; -- not music +SELECT '0123456789012'::ISMN; -- not music + +SELECT '9780123456786'::ISSN; -- not serial +SELECT '9790123456785'::ISSN; -- not serial +SELECT '9791234567896'::ISSN; -- not serial +SELECT '0123456789012'::ISSN; -- not serial + +SELECT '9780123456786'::UPC; -- not a product +SELECT '9771234567898'::UPC; -- not a product +SELECT '9790123456785'::UPC; -- not a product +SELECT '9791234567896'::UPC; -- not a product + +SELECT 'postgresql...'::EAN13; +SELECT 'postgresql...'::ISBN; +SELECT 9780123456786::EAN13; +SELECT 9780123456786::ISBN; + +-- +-- test some comparisons, must yield true +-- +SELECT '12345679'::ISSN = '9771234567003'::EAN13 AS "ok", + 'M-1234-5678-5'::ISMN = '9790123456785'::EAN13 AS "ok", + '9791234567896'::EAN13 != '123456789X'::ISBN AS "nope"; + +-- +-- cleanup +-- +DROP EXTENSION isn; |