Debian Codegraph @

contrib/isn/expected/isn.out

raw
1 --
2 -- Test ISN extension
3 --
4 CREATE EXTENSION isn;
5 -- Check whether any of our opclasses fail amvalidate
6 -- ... they will, because of missing cross-type operators
7 SELECT amname, opcname
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)
29 amname | opcname
30 --------+------------
31 btree | ean13_ops
32 btree | isbn13_ops
33 btree | isbn_ops
34 btree | ismn13_ops
35 btree | ismn_ops
36 btree | issn13_ops
37 btree | issn_ops
38 btree | upc_ops
39 hash | ean13_ops
40 hash | isbn13_ops
41 hash | isbn_ops
42 hash | ismn13_ops
43 hash | ismn_ops
44 hash | issn13_ops
45 hash | issn_ops
46 hash | upc_ops
47 (16 rows)
48
49 --
50 -- test valid conversions
51 --
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
61 (1 row)
62
63 SELECT '9780123456786'::ISBN,
64 '123456789X'::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
70 (1 row)
71
72 SELECT -- new books, shown as ISBN13 even for ISBN...
73 '9791234567896'::ISBN,
74 '9791234567896'::ISBN13::ISBN,
75 '9791234567896'::EAN13::ISBN;
76 isbn | isbn | isbn
77 -----------------+-----------------+-----------------
78 979-123456789-6 | 979-123456789-6 | 979-123456789-6
79 (1 row)
80
81 SELECT '9780123456786'::ISBN13,
82 '123456789X'::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
88 (1 row)
89
90 SELECT '9790123456785'::ISMN,
91 '9790123456785'::EAN13::ISMN,
92 'M123456785'::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
97 (1 row)
98
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
105 (1 row)
106
107 SELECT '9771234567003'::ISSN,
108 '12345679'::ISSN;
109 issn | issn
110 -----------+-----------
111 1234-5679 | 1234-5679
112 (1 row)
113
114 SELECT '9771234567003'::ISSN13,
115 '12345679'::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
121 (1 row)
122
123 SELECT '0123456789012'::UPC,
124 '0123456789012'::EAN13::UPC;
125 upc | upc
126 --------------+--------------
127 123456789012 | 123456789012
128 (1 row)
129
130 --
131 -- test invalid checksums
132 --
133 SELECT '1234567890'::ISBN;
134 ERROR: invalid check digit for ISBN number: "1234567890", should be X
135 LINE 1: SELECT '1234567890'::ISBN;
136 ^
137 SELECT 'M123456780'::ISMN;
138 ERROR: invalid check digit for ISMN number: "M123456780", should be 5
139 LINE 1: SELECT 'M123456780'::ISMN;
140 ^
141 SELECT '12345670'::ISSN;
142 ERROR: invalid check digit for ISSN number: "12345670", should be 9
143 LINE 1: SELECT '12345670'::ISSN;
144 ^
145 SELECT '9780123456780'::ISBN;
146 ERROR: invalid check digit for ISBN number: "9780123456780", should be 6
147 LINE 1: SELECT '9780123456780'::ISBN;
148 ^
149 SELECT '9791234567890'::ISBN13;
150 ERROR: invalid check digit for ISBN number: "9791234567890", should be 6
151 LINE 1: SELECT '9791234567890'::ISBN13;
152 ^
153 SELECT '0123456789010'::UPC;
154 ERROR: invalid check digit for UPC number: "0123456789010", should be 2
155 LINE 1: SELECT '0123456789010'::UPC;
156 ^
157 SELECT '1234567890120'::EAN13;
158 ERROR: invalid check digit for EAN13 number: "1234567890120", should be 8
159 LINE 1: SELECT '1234567890120'::EAN13;
160 ^
161 --
162 -- test invalid conversions
163 --
164 SELECT '9790123456785'::ISBN; -- not a book
165 ERROR: cannot cast ISMN to ISBN for number: "9790123456785"
166 LINE 1: SELECT '9790123456785'::ISBN;
167 ^
168 SELECT '9771234567898'::ISBN; -- not a book
169 ERROR: cannot cast ISSN to ISBN for number: "9771234567898"
170 LINE 1: SELECT '9771234567898'::ISBN;
171 ^
172 SELECT '0123456789012'::ISBN; -- not a book
173 ERROR: cannot cast UPC to ISBN for number: "0123456789012"
174 LINE 1: SELECT '0123456789012'::ISBN;
175 ^
176 SELECT '9790123456785'::ISBN13; -- not a book
177 ERROR: cannot cast ISMN to ISBN for number: "9790123456785"
178 LINE 1: SELECT '9790123456785'::ISBN13;
179 ^
180 SELECT '9771234567898'::ISBN13; -- not a book
181 ERROR: cannot cast ISSN to ISBN for number: "9771234567898"
182 LINE 1: SELECT '9771234567898'::ISBN13;
183 ^
184 SELECT '0123456789012'::ISBN13; -- not a book
185 ERROR: cannot cast UPC to ISBN for number: "0123456789012"
186 LINE 1: SELECT '0123456789012'::ISBN13;
187 ^
188 SELECT '9780123456786'::ISMN; -- not music
189 ERROR: cannot cast ISBN to ISMN for number: "9780123456786"
190 LINE 1: SELECT '9780123456786'::ISMN;
191 ^
192 SELECT '9771234567898'::ISMN; -- not music
193 ERROR: cannot cast ISSN to ISMN for number: "9771234567898"
194 LINE 1: SELECT '9771234567898'::ISMN;
195 ^
196 SELECT '9791234567896'::ISMN; -- not music
197 ERROR: cannot cast ISBN to ISMN for number: "9791234567896"
198 LINE 1: SELECT '9791234567896'::ISMN;
199 ^
200 SELECT '0123456789012'::ISMN; -- not music
201 ERROR: cannot cast UPC to ISMN for number: "0123456789012"
202 LINE 1: SELECT '0123456789012'::ISMN;
203 ^
204 SELECT '9780123456786'::ISSN; -- not serial
205 ERROR: cannot cast ISBN to ISSN for number: "9780123456786"
206 LINE 1: SELECT '9780123456786'::ISSN;
207 ^
208 SELECT '9790123456785'::ISSN; -- not serial
209 ERROR: cannot cast ISMN to ISSN for number: "9790123456785"
210 LINE 1: SELECT '9790123456785'::ISSN;
211 ^
212 SELECT '9791234567896'::ISSN; -- not serial
213 ERROR: cannot cast ISBN to ISSN for number: "9791234567896"
214 LINE 1: SELECT '9791234567896'::ISSN;
215 ^
216 SELECT '0123456789012'::ISSN; -- not serial
217 ERROR: cannot cast UPC to ISSN for number: "0123456789012"
218 LINE 1: SELECT '0123456789012'::ISSN;
219 ^
220 SELECT '9780123456786'::UPC; -- not a product
221 ERROR: cannot cast ISBN to UPC for number: "9780123456786"
222 LINE 1: SELECT '9780123456786'::UPC;
223 ^
224 SELECT '9771234567898'::UPC; -- not a product
225 ERROR: cannot cast ISSN to UPC for number: "9771234567898"
226 LINE 1: SELECT '9771234567898'::UPC;
227 ^
228 SELECT '9790123456785'::UPC; -- not a product
229 ERROR: cannot cast ISMN to UPC for number: "9790123456785"
230 LINE 1: SELECT '9790123456785'::UPC;
231 ^
232 SELECT '9791234567896'::UPC; -- not a product
233 ERROR: cannot cast ISBN to UPC for number: "9791234567896"
234 LINE 1: SELECT '9791234567896'::UPC;
235 ^
236 SELECT 'postgresql...'::EAN13;
237 ERROR: invalid input syntax for EAN13 number: "postgresql..."
238 LINE 1: SELECT 'postgresql...'::EAN13;
239 ^
240 SELECT 'postgresql...'::ISBN;
241 ERROR: invalid input syntax for ISBN number: "postgresql..."
242 LINE 1: SELECT 'postgresql...'::ISBN;
243 ^
244 SELECT 9780123456786::EAN13;
245 ERROR: cannot cast type bigint to ean13
246 LINE 1: SELECT 9780123456786::EAN13;
247 ^
248 SELECT 9780123456786::ISBN;
249 ERROR: cannot cast type bigint to isbn
250 LINE 1: SELECT 9780123456786::ISBN;
251 ^
252 --
253 -- test some comparisons, must yield true
254 --
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";
258 ok | ok | nope
259 ----+----+------
260 t | t | t
261 (1 row)
262
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,
267 errinfo.message,
268 errinfo.detail,
269 errinfo.hint
270 FROM (VALUES ('9780123456786', 'UPC'),
271 ('postgresql...','EAN13'),
272 ('9771234567003','ISSN'))
273 AS a(str,typ),
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 | | | |
280 (3 rows)
281
282 --
283 -- test weak mode
284 --
285 SELECT '2222222222221'::ean13; -- fail
286 ERROR: invalid check digit for EAN13 number: "2222222222221", should be 2
287 LINE 1: SELECT '2222222222221'::ean13;
288 ^
289 SET isn.weak TO TRUE;
290 SELECT '2222222222221'::ean13;
291 ean13
292 ------------------
293 222-222222222-2!
294 (1 row)
295
296 SELECT is_valid('2222222222221'::ean13);
297 is_valid
298 ----------
299 f
300 (1 row)
301
302 SELECT make_valid('2222222222221'::ean13);
303 make_valid
304 -----------------
305 222-222222222-2
306 (1 row)
307
308 SELECT isn_weak(); -- backwards-compatibility wrappers for accessing the GUC
309 isn_weak
310 ----------
311 t
312 (1 row)
313
314 SELECT isn_weak(false);
315 isn_weak
316 ----------
317 f
318 (1 row)
319
320 SHOW isn.weak;
321 isn.weak
322 ----------
323 off
324 (1 row)
325
326 --
327 -- cleanup
328 --
329 DROP EXTENSION isn;