Re: Fix ISSN output truncation when the issue code is nonzero

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Jonah Shafran <jonahshafran(at)gmail(dot)com>
Subject: Re: Fix ISSN output truncation when the issue code is nonzero
Date: 2026-11-19 00:24:15
Message-ID: 236D32A1-E5CC-4C9C-8BFF-0E30A8D8449D@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Nov 18, 2026, at 16:26, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> wrote:
>
> 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.de<v1-0001-Fix-ISSN-output-truncation-when-the-issue-code-is.patch>

Thanks for the patch. I have a small comment:
```
+ /*
+ * 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;
```

While debugging this patch, I noticed that the input isn has already been hyphenated, and ean2ISSN() is a local static function that is only called by ean2string(). Actually, your new logic of returning directly relies on isn being hyphenated. So I don't think we need to dehyphenate isn. Instead, we can just compare:
```
if (strncmp(isn + 13, "00", 2) != 0)
return;
```

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Joao Rito 2026-11-19 00:18:17 Re: XMLTable treats a column of a domain over xml as a non-xml column