5 -- Check whether any of our opclasses fail amvalidate
6 -- ... they will, because of missing cross-type operators
8 FROM (SELECT amname, opcname, opc.oid
9 FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
10 WHERE opc.oid >= 16384
11 ORDER BY 1, 2 OFFSET 0) ss
12 WHERE NOT amvalidate(oid);
13 INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s)
14 INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s)
15 INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s)
16 INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s)
17 INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s)
18 INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s)
19 INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s)
20 INFO: operator family "isn_ops" of access method btree is missing cross-type operator(s)
21 INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s)
22 INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s)
23 INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s)
24 INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s)
25 INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s)
26 INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s)
27 INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s)
28 INFO: operator family "isn_ops" of access method hash is missing cross-type operator(s)
50 -- test valid conversions
52 SELECT '9780123456786'::EAN13, -- old book
53 '9790123456785'::EAN13, -- music
54 '9791234567896'::EAN13, -- new book
55 '9771234567898'::EAN13, -- serial
56 '0123456789012'::EAN13, -- upc
57 '1234567890128'::EAN13;
58 ean13 | ean13 | ean13 | ean13 | ean13 | ean13
59 -------------------+-------------------+-----------------+-------------------+-----------------+-----------------
60 978-0-12-345678-6 | 979-0-1234-5678-5 | 979-123456789-6 | 977-1234-567-89-8 | 012-345678901-2 | 123-456789012-8
63 SELECT '9780123456786'::ISBN,
65 '9780123456786'::ISBN13::ISBN,
66 '9780123456786'::EAN13::ISBN;
67 isbn | isbn | isbn | isbn
68 ---------------+---------------+---------------+---------------
69 0-12-345678-9 | 1-234-56789-X | 0-12-345678-9 | 0-12-345678-9
72 SELECT -- new books, shown as ISBN13 even for ISBN...
73 '9791234567896'::ISBN,
74 '9791234567896'::ISBN13::ISBN,
75 '9791234567896'::EAN13::ISBN;
77 -----------------+-----------------+-----------------
78 979-123456789-6 | 979-123456789-6 | 979-123456789-6
81 SELECT '9780123456786'::ISBN13,
83 '9791234567896'::ISBN13,
84 '9791234567896'::EAN13::ISBN13;
85 isbn13 | isbn13 | isbn13 | isbn13
86 -------------------+-------------------+-----------------+-----------------
87 978-0-12-345678-6 | 978-1-234-56789-7 | 979-123456789-6 | 979-123456789-6
90 SELECT '9790123456785'::ISMN,
91 '9790123456785'::EAN13::ISMN,
93 'M-1234-5678-5'::ISMN;
94 ismn | ismn | ismn | ismn
95 ---------------+---------------+---------------+---------------
96 M-1234-5678-5 | M-1234-5678-5 | M-1234-5678-5 | M-1234-5678-5
99 SELECT '9790123456785'::ISMN13,
100 'M123456785'::ISMN13,
101 'M-1234-5678-5'::ISMN13;
102 ismn13 | ismn13 | ismn13
103 -------------------+-------------------+-------------------
104 979-0-1234-5678-5 | 979-0-1234-5678-5 | 979-0-1234-5678-5
107 SELECT '9771234567003'::ISSN,
110 -----------+-----------
111 1234-5679 | 1234-5679
114 SELECT '9771234567003'::ISSN13,
116 '9771234567898'::ISSN13,
117 '9771234567898'::EAN13::ISSN13;
118 issn13 | issn13 | issn13 | issn13
119 -------------------+-------------------+-------------------+-------------------
120 977-1234-567-00-3 | 977-1234-567-00-3 | 977-1234-567-89-8 | 977-1234-567-89-8
123 SELECT '0123456789012'::UPC,
124 '0123456789012'::EAN13::UPC;
126 --------------+--------------
127 123456789012 | 123456789012
131 -- test invalid checksums
133 SELECT '1234567890'::ISBN;
134 ERROR: invalid check digit for ISBN number: "1234567890", should be X
135 LINE 1: SELECT '1234567890'::ISBN;
137 SELECT 'M123456780'::ISMN;
138 ERROR: invalid check digit for ISMN number: "M123456780", should be 5
139 LINE 1: SELECT 'M123456780'::ISMN;
141 SELECT '12345670'::ISSN;
142 ERROR: invalid check digit for ISSN number: "12345670", should be 9
143 LINE 1: SELECT '12345670'::ISSN;
145 SELECT '9780123456780'::ISBN;
146 ERROR: invalid check digit for ISBN number: "9780123456780", should be 6
147 LINE 1: SELECT '9780123456780'::ISBN;
149 SELECT '9791234567890'::ISBN13;
150 ERROR: invalid check digit for ISBN number: "9791234567890", should be 6
151 LINE 1: SELECT '9791234567890'::ISBN13;
153 SELECT '0123456789010'::UPC;
154 ERROR: invalid check digit for UPC number: "0123456789010", should be 2
155 LINE 1: SELECT '0123456789010'::UPC;
157 SELECT '1234567890120'::EAN13;
158 ERROR: invalid check digit for EAN13 number: "1234567890120", should be 8
159 LINE 1: SELECT '1234567890120'::EAN13;
162 -- test invalid conversions
164 SELECT '9790123456785'::ISBN; -- not a book
165 ERROR: cannot cast ISMN to ISBN for number: "9790123456785"
166 LINE 1: SELECT '9790123456785'::ISBN;
168 SELECT '9771234567898'::ISBN; -- not a book
169 ERROR: cannot cast ISSN to ISBN for number: "9771234567898"
170 LINE 1: SELECT '9771234567898'::ISBN;
172 SELECT '0123456789012'::ISBN; -- not a book
173 ERROR: cannot cast UPC to ISBN for number: "0123456789012"
174 LINE 1: SELECT '0123456789012'::ISBN;
176 SELECT '9790123456785'::ISBN13; -- not a book
177 ERROR: cannot cast ISMN to ISBN for number: "9790123456785"
178 LINE 1: SELECT '9790123456785'::ISBN13;
180 SELECT '9771234567898'::ISBN13; -- not a book
181 ERROR: cannot cast ISSN to ISBN for number: "9771234567898"
182 LINE 1: SELECT '9771234567898'::ISBN13;
184 SELECT '0123456789012'::ISBN13; -- not a book
185 ERROR: cannot cast UPC to ISBN for number: "0123456789012"
186 LINE 1: SELECT '0123456789012'::ISBN13;
188 SELECT '9780123456786'::ISMN; -- not music
189 ERROR: cannot cast ISBN to ISMN for number: "9780123456786"
190 LINE 1: SELECT '9780123456786'::ISMN;
192 SELECT '9771234567898'::ISMN; -- not music
193 ERROR: cannot cast ISSN to ISMN for number: "9771234567898"
194 LINE 1: SELECT '9771234567898'::ISMN;
196 SELECT '9791234567896'::ISMN; -- not music
197 ERROR: cannot cast ISBN to ISMN for number: "9791234567896"
198 LINE 1: SELECT '9791234567896'::ISMN;
200 SELECT '0123456789012'::ISMN; -- not music
201 ERROR: cannot cast UPC to ISMN for number: "0123456789012"
202 LINE 1: SELECT '0123456789012'::ISMN;
204 SELECT '9780123456786'::ISSN; -- not serial
205 ERROR: cannot cast ISBN to ISSN for number: "9780123456786"
206 LINE 1: SELECT '9780123456786'::ISSN;
208 SELECT '9790123456785'::ISSN; -- not serial
209 ERROR: cannot cast ISMN to ISSN for number: "9790123456785"
210 LINE 1: SELECT '9790123456785'::ISSN;
212 SELECT '9791234567896'::ISSN; -- not serial
213 ERROR: cannot cast ISBN to ISSN for number: "9791234567896"
214 LINE 1: SELECT '9791234567896'::ISSN;
216 SELECT '0123456789012'::ISSN; -- not serial
217 ERROR: cannot cast UPC to ISSN for number: "0123456789012"
218 LINE 1: SELECT '0123456789012'::ISSN;
220 SELECT '9780123456786'::UPC; -- not a product
221 ERROR: cannot cast ISBN to UPC for number: "9780123456786"
222 LINE 1: SELECT '9780123456786'::UPC;
224 SELECT '9771234567898'::UPC; -- not a product
225 ERROR: cannot cast ISSN to UPC for number: "9771234567898"
226 LINE 1: SELECT '9771234567898'::UPC;
228 SELECT '9790123456785'::UPC; -- not a product
229 ERROR: cannot cast ISMN to UPC for number: "9790123456785"
230 LINE 1: SELECT '9790123456785'::UPC;
232 SELECT '9791234567896'::UPC; -- not a product
233 ERROR: cannot cast ISBN to UPC for number: "9791234567896"
234 LINE 1: SELECT '9791234567896'::UPC;
236 SELECT 'postgresql...'::EAN13;
237 ERROR: invalid input syntax for EAN13 number: "postgresql..."
238 LINE 1: SELECT 'postgresql...'::EAN13;
240 SELECT 'postgresql...'::ISBN;
241 ERROR: invalid input syntax for ISBN number: "postgresql..."
242 LINE 1: SELECT 'postgresql...'::ISBN;
244 SELECT 9780123456786::EAN13;
245 ERROR: cannot cast type bigint to ean13
246 LINE 1: SELECT 9780123456786::EAN13;
248 SELECT 9780123456786::ISBN;
249 ERROR: cannot cast type bigint to isbn
250 LINE 1: SELECT 9780123456786::ISBN;
253 -- test some comparisons, must yield true
255 SELECT '12345679'::ISSN = '9771234567003'::EAN13 AS "ok",
256 'M-1234-5678-5'::ISMN = '9790123456785'::EAN13 AS "ok",
257 '9791234567896'::EAN13 != '123456789X'::ISBN AS "nope";
263 -- test non-error-throwing input API
264 SELECT str as isn, typ as "type",
265 pg_input_is_valid(str,typ) as ok,
266 errinfo.sql_error_code,
270 FROM (VALUES ('9780123456786', 'UPC'),
271 ('postgresql...','EAN13'),
272 ('9771234567003','ISSN'))
274 LATERAL pg_input_error_info(a.str, a.typ) as errinfo;
275 isn | type | ok | sql_error_code | message | detail | hint
276 ---------------+-------+----+----------------+--------------------------------------------------------+--------+------
277 9780123456786 | UPC | f | 22P02 | cannot cast ISBN to UPC for number: "9780123456786" | |
278 postgresql... | EAN13 | f | 22P02 | invalid input syntax for EAN13 number: "postgresql..." | |
279 9771234567003 | ISSN | t | | | |