バージョンごとのドキュメント一覧

F.21. isn — 国際標準番号(ISBN、EAN、UPC等)のためのデータ型 #

<title>isn &mdash; data types for international standard numbers (ISBN, EAN, UPC, etc.)</title>

The <filename>isn</filename> module provides data types for the following international product numbering standards: EAN13, UPC, ISBN (books), ISMN (music), and ISSN (serials). Numbers are validated on input according to a hard-coded list of prefixes; this list of prefixes is also used to hyphenate numbers on output. Since new prefixes are assigned from time to time, the list of prefixes may be out of date. It is hoped that a future version of this module will obtain the prefix list from one or more tables that can be easily updated by users as needed; however, at present, the list can only be updated by modifying the source code and recompiling. Alternatively, prefix validation and hyphenation support may be dropped from a future version of this module. isnモジュールは、EAN13、UPC、ISBN (書籍)、ISMN (音楽)、ISSN (逐次刊行物)という国際的な標準製品番号に従うデータ型を提供します。 番号は入力時にハードコードされた接頭辞の一覧に基づいて検証されます。 この接頭辞の一覧は出力時に数字にハイフンを付けるのにも使われます。 新しい接頭辞が時々追加されますので、接頭辞の一覧は古くなっているかもしれません。 このモジュールの将来のバージョンでは、必要なときにユーザが簡単に更新できる一つもしくは複数のテーブルから接頭辞の一覧を取得することが望まれます。 しかし、現時点では、一覧はソースコードを修正し再コンパイルすることでしか更新できません。 あるいは、接頭辞の検証とハイフン付けのサポートはこのモジュールの将来のバージョンからは外されるかもしれません。

This module is considered <quote>trusted</quote>, that is, it can be installed by non-superusers who have <literal>CREATE</literal> privilege on the current database. このモジュールはtrustedと見なされます。つまり、現在のデータベースに対してCREATE権限を持つ非スーパーユーザがインストールできます。

F.21.1. データ型 #

<title>Data Types</title>

<xref linkend="isn-datatypes"/> shows the data types provided by the <filename>isn</filename> module. 表 F.11isnモジュールで提供されるデータ型を示します。

表F.11 isnデータ型

<title><filename>isn</filename> Data Types</title>
データ型説明
EAN13 European Article Numbers, always displayed in the EAN13 display format ヨーロッパ統一商品コード。 常にEAN13用表示形式で表示されます。
ISBN13 International Standard Book Numbers to be displayed in the new EAN13 display format 国際標準図書番号。 新しいEAN13用表示形式で表示されます。
ISMN13 International Standard Music Numbers to be displayed in the new EAN13 display format 国際標準楽譜番号。 新しいEAN13用表示形式で表示されます。
ISSN13 International Standard Serial Numbers to be displayed in the new EAN13 display format 国際標準逐次刊行物番号。 新しいEAN13用表示形式で表示されます。
ISBN International Standard Book Numbers to be displayed in the old short display format 国際標準図書番号。 旧式の簡略表示形式で表示されます。
ISMN International Standard Music Numbers to be displayed in the old short display format 国際標準楽譜番号。 旧式の簡略表示形式で表示されます。
ISSN International Standard Serial Numbers to be displayed in the old short display format 国際標準逐次刊行物番号。 旧式の簡略表示形式で表示されます。
UPC Universal Product Codes 統一商品コード。

Some notes: 数点注意事項があります。

  1. <para>ISBN13, ISMN13, ISSN13 numbers are all EAN13 numbers.</para>

    ISBN13、ISMN13、ISSN13番号はすべてEAN13数値です。

  2. <para>EAN13 numbers aren't always ISBN13, ISMN13 or ISSN13 (some are).</para>

    EAN13番号は必ずISBN13、ISMN13、ISSN13のいずれかであるという訳ではありません (一部はそうです)。

  3. <para>Some ISBN13 numbers can be displayed as ISBN.</para>

    一部のISBN13番号はISBNとして表示可能です。

  4. <para>Some ISMN13 numbers can be displayed as ISMN.</para>

    一部のISMN13番号はISMNとして表示可能です。

  5. <para>Some ISSN13 numbers can be displayed as ISSN.</para>

    一部のISSN13番号はISSNとして表示可能です。

  6. <para>UPC numbers are a subset of the EAN13 numbers (they are basically EAN13 without the first <literal>0</literal> digit).</para>

    UPC番号はEAN13番号の部分集合です(基本的にはEAN13から先頭の0の数字を取り除いたものです)。

  7. <para>All UPC, ISBN, ISMN and ISSN numbers can be represented as EAN13 numbers.</para>

    すべてのUPC、ISBN、ISMN、ISSNはEAN13番号として表現可能です。

Internally, all these types use the same representation (a 64-bit integer), and all are interchangeable. Multiple types are provided to control display formatting and to permit tighter validity checking of input that is supposed to denote one particular type of number. すべての型は内部的には同一表現(64ビット整数)を使用し、すべて相互交換が可能です。 複数の型は、表示書式を制御する、および、番号のある特定の型を表さなければならない入力に対する有効性検査をより強く行えるようにするために提供されています。

The <type>ISBN</type>, <type>ISMN</type>, and <type>ISSN</type> types will display the short version of the number (ISxN 10) whenever it's possible, and will show ISxN 13 format for numbers that do not fit in the short version. The <type>EAN13</type>, <type>ISBN13</type>, <type>ISMN13</type> and <type>ISSN13</type> types will always display the long version of the ISxN (EAN13). ISBNISMNISSN型では、可能ならば番号の簡略表示形式(ISxN 10)で表示されます。 簡略形式に合わない番号ではISxN 13書式で表示されます。 EAN13ISBN13ISMN13ISSN13型では常にISxNの長めの形式(EAN13)で表示されます。

F.21.2. キャスト #

<title>Casts</title>

The <filename>isn</filename> module provides the following pairs of type casts: isnモジュールは以下の型の組合せに関するキャストを提供します。

  • ISBN13 <=> EAN13

  • ISMN13 <=> EAN13

  • ISSN13 <=> EAN13

  • ISBN <=> EAN13

  • ISMN <=> EAN13

  • ISSN <=> EAN13

  • UPC <=> EAN13

  • ISBN <=> ISBN13

  • ISMN <=> ISMN13

  • ISSN <=> ISSN13

When casting from <type>EAN13</type> to another type, there is a run-time check that the value is within the domain of the other type, and an error is thrown if not. The other casts are simply relabelings that will always succeed. EAN13から他の型へキャストする時、その値が他の型のドメイン内であるかどうか実行時に検査が行われます。 ドメイン内になければエラーが発生します。 他のキャストでは単にラベル付けを再実行するだけですので、常に成功します。

F.21.3. 関数と演算子 #

<title>Functions and Operators</title>

The <filename>isn</filename> 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 <xref linkend="isn-functions"/>. In this table, <type>isn</type> means any one of the module's data types. isnモジュールは標準的な比較演算子とこれらデータ型すべてに対するB-treeおよびハッシュインデックスサポートを提供します。 さらに、表 F.12で示される複数の特化した関数も存在します。 以下の表ではisnはこのモジュールのデータ型のいずれか1つを意味します。

表F.12 isn Functions

Function 関数

Description 説明

isn_weak ( boolean ) → boolean

Sets the weak input mode, and returns new setting. weak入力モードを設定し、新しい設定を返します。

isn_weak () → boolean

Returns the current status of the weak mode. weakモードの現在の状態を返します。

make_valid ( isn ) → isn

Validates an invalid number (clears the invalid flag). 無効な番号を検証します(無効フラグを消去します)。

is_valid ( isn ) → boolean

Checks for the presence of the invalid flag. 無効フラグの有無を検査します。


<firstterm>Weak</firstterm> 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. weakモードは無効なデータをテーブルに挿入できるようにするために使用されます。 無効とは間違ったチェックディジットを意味するものであり、番号自体は存在します。

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. このweakモードを使いたいと考えるのは何故でしょうか。 大規模なISBN番号群があり、その内の多くが何らかの理由で間違ったチェックディジットを持つことはあり得ます。 (印刷された一覧をスキャンしてOCRした結果番号を間違えた場合、手作業で番号を取り出した場合などがあり得ます。) とにかく、こうした混乱は整理したいことですが、データベース内に番号をすべて取り込んで、より簡単に情報を検査し有効にすることができるように、外部ツールを使用してデータベース内の無効な番号の位置を特定したいと思うかも知れません。 例えば、テーブル内の無効な番号をすべて選択したいと思うかも知れません。

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 (<literal>!</literal>) at the end, for example <literal>0-11-000322-5!</literal>. This invalid marker can be checked with the <function>is_valid</function> function and cleared with the <function>make_valid</function> function. weakモードを使用して無効な番号をテーブルに挿入する時、番号は修正されたチェックディジット付きで挿入されますが、最後にイクスクラメーション印(!)付きで、例えば0-11-000322-5!と表示されます。 この無効印はis_valid関数を使って検査することができ、また、 make_valid関数で消去することができます。

You can also force the insertion of invalid numbers even when not in the weak mode, by appending the <literal>!</literal> character at the end of the number. また、番号の最後に!文字を付与することで、weakモードでなくとも無効な番号を強制的に挿入することもできます。

Another special feature is that during input, you can write <literal>?</literal> in place of the check digit, and the correct check digit will be inserted automatically. この他の入力における特殊な機能として、チェックディジットとして?を書くことができます。 これにより正確なチェックディジットが自動的に挿入されます。

F.21.4. 例 #

<title>Examples</title>

&#45;-Using the types directly:

---型を直接使う
SELECT isbn('978-0-393-04002-9');
SELECT isbn13('0901690546');
SELECT issn('1436-4522');


&#45;-Casting types:
&#45;- note that you can only cast from ean13 to another type when the
&#45;- number would be valid in the realm of the target type;
&#45;- thus, the following will NOT work: select isbn(ean13('0220356483481'));
&#45;- but these will:

--型キャスト
-- 番号が対象の型の範囲として有効な場合にのみean13から他の型へキャストできることに注意
-- そのため、次のようなものは上手くいかない: select isbn(ean13('0220356483481'));
-- しかし以下は上手くいく
SELECT upc(ean13('0220356483481'));
SELECT ean13(upc('220356483481'));


&#45;-Create a table with a single column to hold ISBN numbers:

--ISBN番号を保持する列が1つあるテーブルを作成する
CREATE TABLE test (id isbn);
INSERT INTO test VALUES('9780393040029');


&#45;-Automatically calculate check digits (observe the '?'):

--チェックディジットを自動的に計算する('?'を見よ)
INSERT INTO test VALUES('220500896?');
INSERT INTO test VALUES('978055215372?');

SELECT issn('3251231?');
SELECT ismn('979047213542?');


&#45;-Using the weak mode:

--weakモードを利用する
SELECT isn_weak(true);
INSERT INTO test VALUES('978-0-11-000533-4');
INSERT INTO test VALUES('9780141219307');
INSERT INTO test VALUES('2-205-00876-X');
SELECT isn_weak(false);

SELECT id FROM test WHERE NOT is_valid(id);
UPDATE test SET id = make_valid(id) WHERE id = '2-205-00876-X!';

SELECT * FROM test;

SELECT isbn13(id) FROM test;

F.21.5. 参考文献 #

<title>Bibliography</title>

The information to implement this module was collected from several sites, including: 本モジュールを実装するための情報は以下を含むいくつかのサイトを通して集められました。

The prefixes used for hyphenation were also compiled from: ハイフン付けに使用した接頭辞も以下から集められました。

Care was taken during the creation of the algorithms and they were meticulously verified against the suggested algorithms in the official ISBN, ISMN, ISSN User Manuals. アルゴリズムの作成には注意を払い、公式ISBN、ISMN、ISSNユーザマニュアルで提示されたアルゴリズムに対して念入り過ぎるほど検証されました。

F.21.6. 作者 #

<title>Author</title>

Germán Méndez Bravo (Kronuz), 2004–2006

This module was inspired by Garrett A. Wollman's <filename>isbn_issn</filename> code. 本モジュールはGarrett A. Wollmanのisbn_issnコードに触発されたものです。