postgresql_16:9.6.21.3 Functions and Operators
PostgreSQL 16 > Appendixes > Additional Supplied Modules and Extensions > isn — data types for international standard numbers (ISBN, EAN, UPC, etc.) > Functions and Operators
The isn module provides the standard comparison operators, plus B-tree and hash indexing support for all these data types. In addition there are several specialized functions; shown in (see isn-functions). In this table, isn means any one of the module's data types.
| Function Description | | --- | | isn_weak ( boolean ) boolean Sets the weak input mode, and returns new setting. | | isn_weak () boolean Returns the current status of the weak mode. | | make_valid ( isn ) isn Validates an invalid number (clears the invalid flag). | | is_valid ( isn ) boolean Checks for the presence of the invalid flag. |
*Weak* mode is used to be able to insert invalid data into a table. Invalid means the check digit is wrong, not that there are missing numbers.
Why would you want to use the weak mode? Well, it could be that you have a huge collection of ISBN numbers, and that there are so many of them that for weird reasons some have the wrong check digit (perhaps the numbers were scanned from a printed list and the OCR got the numbers wrong, perhaps the numbers were manually captured... who knows). Anyway, the point is you might want to clean the mess up, but you still want to be able to have all the numbers in your database and maybe use an external tool to locate the invalid numbers in the database so you can verify the information and validate it more easily; so for example you'd want to select all the invalid numbers in the table.
When you insert invalid numbers in a table using the weak mode, the number will be inserted with the corrected check digit, but it will be displayed with an exclamation mark (!) at the end, for example 0-11-000322-5!. This invalid marker can be checked with the is_valid function and cleared with the make_valid function.
You can also force the insertion of invalid numbers even when not in the weak mode, by appending the ! character at the end of the number.
Another special feature is that during input, you can write ? in place of the check digit, and the correct check digit will be inserted automatically.