Hi
As reported in [1], a 13-digit issn with a nonzero issue publication
code is currently displayed in its 8-digit short form, which drops that
code. Values that differ only in the issue code are therefore displayed
identically while comparing unequal:
== master ==
psql (20devel)
Type "help" for help.
postgres=# create extension isn;
CREATE EXTENSION
postgres=# with j (v1,v2) as (
values ('12345679'::issn, '9771234567898'::issn)
)
select v1,v2,v1=v2 from j;
v1 | v2 | ?column?
-----------+-----------+----------
1234-5679 | 1234-5679 | f
(1 row)
The attached patch adds a guard in ean2ISSN to keep the full issn in
case the given isn has an issue publication code, therefore avoiding
truncation.
== patched ==
psql (20devel)
Type "help" for help.
postgres=# create extension isn;
CREATE EXTENSION
postgres=# with j (v1,v2) as (
values ('12345679'::issn, '9771234567898'::issn)
)
select v1,v2,v1=v2 from j;
v1 | v2 | ?column?
-----------+-------------------+----------
1234-5679 | 977-1234-567-89-8 | f
(1 row)
Best, Jim
1 -
https://www.postgresql.org/message-id/4e6c2fc9-5389-4958-a432-bb0ee5348ad0%40uni-muenster.deFrom a433de80e08656cf41afe4b6e3712ec71dfcadc0 Mon Sep 17 00:00:00 2001
From: Jim Jones <[email protected]>
Date: Wed, 18 Nov 2026 08:18:51 +0100
Subject: [PATCH v1] Fix ISSN output truncation when the issue code is nonzero
ISSN output always used the 8-digit short form, which drops the
two-digit issue publication code of an ISSN-13. Values that differ
only in that code were displayed identically while comparing unequal.
Use the short form only when the code is 00.
Author: Jim Jones <[email protected]>
Reviewed-by: Jonah Shafran <[email protected]>
---
contrib/isn/expected/isn.out | 9 +++++----
contrib/isn/isn.c | 9 +++++++++
contrib/isn/sql/isn.sql | 3 ++-
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/contrib/isn/expected/isn.out b/contrib/isn/expected/isn.out
index c533768d926..fa1759b55d1 100644
--- a/contrib/isn/expected/isn.out
+++ b/contrib/isn/expected/isn.out
@@ -105,10 +105,11 @@ SELECT '9790123456785'::ISMN13,
(1 row)
SELECT '9771234567003'::ISSN,
- '12345679'::ISSN;
- issn | issn
------------+-----------
- 1234-5679 | 1234-5679
+ '12345679'::ISSN,
+ '9771234567898'::ISSN;
+ issn | issn | issn
+-----------+-----------+-------------------
+ 1234-5679 | 1234-5679 | 977-1234-567-89-8
(1 row)
SELECT '9771234567003'::ISSN13,
diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c
index a1d2f26158a..c60b05a3797 100644
--- a/contrib/isn/isn.c
+++ b/contrib/isn/isn.c
@@ -472,6 +472,15 @@ static inline void
ean2ISSN(char *isn)
{
unsigned check;
+ char digits[MAXEAN13LEN + 1];
+
+ /*
+ * If the issue publication code is non-zero, we shouldn't
+ * perform any truncation
+ */
+ dehyphenate(digits, isn);
+ if (strncmp(digits + 10, "00", 2) != 0)
+ return;
/* the number should come in this format: 977-0000-000-00-0 */
/* Strip the first part, crop, and calculate the new check digit */
diff --git a/contrib/isn/sql/isn.sql b/contrib/isn/sql/isn.sql
index 043e5580b0d..270f5c38a22 100644
--- a/contrib/isn/sql/isn.sql
+++ b/contrib/isn/sql/isn.sql
@@ -48,7 +48,8 @@ SELECT '9790123456785'::ISMN13,
'M-1234-5678-5'::ISMN13;
SELECT '9771234567003'::ISSN,
- '12345679'::ISSN;
+ '12345679'::ISSN,
+ '9771234567898'::ISSN;
SELECT '9771234567003'::ISSN13,
'12345679'::ISSN13,
--
2.56.1