Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 977b9e43ddbf791a68788d984b14383d > files > 412

postgresql9.3-docs-9.3.9-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>isn</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.3.9 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Additional Supplied Modules"
HREF="contrib.html"><LINK
REL="PREVIOUS"
TITLE="intarray"
HREF="intarray.html"><LINK
REL="NEXT"
TITLE="lo"
HREF="lo.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2015-06-13T20:07:22"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.3.9 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="intarray"
HREF="intarray.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="contrib.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Appendix F. Additional Supplied Modules</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="lo"
HREF="lo.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="ISN"
>F.19. isn</A
></H1
><P
>  The <TT
CLASS="FILENAME"
>isn</TT
> 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 obtained 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.
 </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN153031"
>F.19.1. Data Types</A
></H2
><P
>   <A
HREF="isn.html#ISN-DATATYPES"
>Table F-10</A
> shows the data types provided by
   the <TT
CLASS="FILENAME"
>isn</TT
> module.
  </P
><DIV
CLASS="TABLE"
><A
NAME="ISN-DATATYPES"
></A
><P
><B
>Table F-10. <TT
CLASS="FILENAME"
>isn</TT
> Data Types</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Data Type</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="TYPE"
>EAN13</TT
></TD
><TD
>       European Article Numbers, always displayed in the EAN13 display format
      </TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>ISBN13</TT
></TD
><TD
>       International Standard Book Numbers to be displayed in
       the new EAN13 display format
      </TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>ISMN13</TT
></TD
><TD
>       International Standard Music Numbers to be displayed in
       the new EAN13 display format
      </TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>ISSN13</TT
></TD
><TD
>       International Standard Serial Numbers to be displayed in the new
       EAN13 display format
      </TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>ISBN</TT
></TD
><TD
>       International Standard Book Numbers to be displayed in the old
       short display format
      </TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>ISMN</TT
></TD
><TD
>       International Standard Music Numbers to be displayed in the
       old short display format
      </TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>ISSN</TT
></TD
><TD
>       International Standard Serial Numbers to be displayed in the
       old short display format
      </TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>UPC</TT
></TD
><TD
>       Universal Product Codes
      </TD
></TR
></TBODY
></TABLE
></DIV
><P
>   Some notes:
  </P
><P
></P
><OL
TYPE="1"
><LI
><P
>ISBN13, ISMN13, ISSN13 numbers are all EAN13 numbers.</P
></LI
><LI
><P
>EAN13 numbers aren't always ISBN13, ISMN13 or ISSN13 (some
    are).</P
></LI
><LI
><P
>Some ISBN13 numbers can be displayed as ISBN.</P
></LI
><LI
><P
>Some ISMN13 numbers can be displayed as ISMN.</P
></LI
><LI
><P
>Some ISSN13 numbers can be displayed as ISSN.</P
></LI
><LI
><P
>UPC numbers are a subset of the EAN13 numbers (they are basically
    EAN13 without the first <TT
CLASS="LITERAL"
>0</TT
> digit).</P
></LI
><LI
><P
>All UPC, ISBN, ISMN and ISSN numbers can be represented as EAN13
    numbers.</P
></LI
></OL
><P
>   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.
  </P
><P
>   The <TT
CLASS="TYPE"
>ISBN</TT
>, <TT
CLASS="TYPE"
>ISMN</TT
>, and <TT
CLASS="TYPE"
>ISSN</TT
> 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 <TT
CLASS="TYPE"
>EAN13</TT
>, <TT
CLASS="TYPE"
>ISBN13</TT
>, <TT
CLASS="TYPE"
>ISMN13</TT
> and
   <TT
CLASS="TYPE"
>ISSN13</TT
> types will always display the long version of the ISxN
   (EAN13).
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN153103"
>F.19.2. Casts</A
></H2
><P
>   The <TT
CLASS="FILENAME"
>isn</TT
> module provides the following pairs of type casts:
  </P
><P
></P
><UL
><LI
><P
>     ISBN13 &lt;=&gt; EAN13
    </P
></LI
><LI
><P
>     ISMN13 &lt;=&gt; EAN13
    </P
></LI
><LI
><P
>     ISSN13 &lt;=&gt; EAN13
    </P
></LI
><LI
><P
>     ISBN &lt;=&gt; EAN13
    </P
></LI
><LI
><P
>     ISMN &lt;=&gt; EAN13
    </P
></LI
><LI
><P
>     ISSN &lt;=&gt; EAN13
    </P
></LI
><LI
><P
>     UPC  &lt;=&gt; EAN13
    </P
></LI
><LI
><P
>     ISBN &lt;=&gt; ISBN13
    </P
></LI
><LI
><P
>     ISMN &lt;=&gt; ISMN13
    </P
></LI
><LI
><P
>     ISSN &lt;=&gt; ISSN13
    </P
></LI
></UL
><P
>   When casting from <TT
CLASS="TYPE"
>EAN13</TT
> 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.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN153130"
>F.19.3. Functions and Operators</A
></H2
><P
>   The <TT
CLASS="FILENAME"
>isn</TT
> 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 <A
HREF="isn.html#ISN-FUNCTIONS"
>Table F-11</A
>.
   In this table,
   <TT
CLASS="TYPE"
>isn</TT
> means any one of the module's data types.
  </P
><DIV
CLASS="TABLE"
><A
NAME="ISN-FUNCTIONS"
></A
><P
><B
>Table F-11. <TT
CLASS="FILENAME"
>isn</TT
> Functions</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>Function</TH
><TH
>Returns</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><CODE
CLASS="FUNCTION"
>isn_weak(boolean)</CODE
></TD
><TD
><TT
CLASS="TYPE"
>boolean</TT
></TD
><TD
>Sets the weak input mode (returns new setting)</TD
></TR
><TR
><TD
><CODE
CLASS="FUNCTION"
>isn_weak()</CODE
></TD
><TD
><TT
CLASS="TYPE"
>boolean</TT
></TD
><TD
>Gets the current status of the weak mode</TD
></TR
><TR
><TD
><CODE
CLASS="FUNCTION"
>make_valid(isn)</CODE
></TD
><TD
><TT
CLASS="TYPE"
>isn</TT
></TD
><TD
>Validates an invalid number (clears the invalid flag)</TD
></TR
><TR
><TD
><CODE
CLASS="FUNCTION"
>is_valid(isn)</CODE
></TD
><TD
><TT
CLASS="TYPE"
>boolean</TT
></TD
><TD
>Checks for the presence of the invalid flag</TD
></TR
></TBODY
></TABLE
></DIV
><P
>   <I
CLASS="FIRSTTERM"
>Weak</I
> 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.
  </P
><P
>   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.
  </P
><P
>   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 (<TT
CLASS="LITERAL"
>!</TT
>) at the end, for example
   <TT
CLASS="LITERAL"
>0-11-000322-5!</TT
>.  This invalid marker can be checked with
   the <CODE
CLASS="FUNCTION"
>is_valid</CODE
> function and cleared with the
   <CODE
CLASS="FUNCTION"
>make_valid</CODE
> function.
  </P
><P
>   You can also force the insertion of invalid numbers even when not in the
   weak mode, by appending the <TT
CLASS="LITERAL"
>!</TT
> character at the end of the
   number.
  </P
><P
>   Another special feature is that during input, you can write
   <TT
CLASS="LITERAL"
>?</TT
> in place of the check digit, and the correct check digit
   will be inserted automatically.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN153188"
>F.19.4. Examples</A
></H2
><PRE
CLASS="PROGRAMLISTING"
>--Using the types directly:
SELECT isbn('978-0-393-04002-9');
SELECT isbn13('0901690546');
SELECT issn('1436-4522');

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

--Create a table with a single column to hold ISBN numbers:
CREATE TABLE test (id isbn);
INSERT INTO test VALUES('9780393040029');

--Automatically calculate check digits (observe the '?'):
INSERT INTO test VALUES('220500896?');
INSERT INTO test VALUES('978055215372?');

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

--Using the weak mode:
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;</PRE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN153191"
>F.19.5. Bibliography</A
></H2
><P
>   The information to implement this module was collected from
   several sites, including:
   <P
></P
></P><UL
><LI
><P
><A
HREF="http://www.isbn-international.org/"
TARGET="_top"
>http://www.isbn-international.org/</A
></P
></LI
><LI
><P
><A
HREF="http://www.issn.org/"
TARGET="_top"
>http://www.issn.org/</A
></P
></LI
><LI
><P
><A
HREF="http://www.ismn-international.org/"
TARGET="_top"
>http://www.ismn-international.org/</A
></P
></LI
><LI
><P
><A
HREF="http://www.wikipedia.org/"
TARGET="_top"
>http://www.wikipedia.org/</A
></P
></LI
></UL
><P>

   The prefixes used for hyphenation were also compiled from:
   <P
></P
></P><UL
><LI
><P
><A
HREF="http://www.gs1.org/productssolutions/idkeys/support/prefix_list.html"
TARGET="_top"
>http://www.gs1.org/productssolutions/idkeys/support/prefix_list.html</A
></P
></LI
><LI
><P
><A
HREF="http://www.isbn-international.org/en/identifiers.html"
TARGET="_top"
>http://www.isbn-international.org/en/identifiers.html</A
></P
></LI
><LI
><P
><A
HREF="http://www.ismn-international.org/ranges.html"
TARGET="_top"
>http://www.ismn-international.org/ranges.html</A
></P
></LI
></UL
><P>

   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.
  </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN153217"
>F.19.6. Author</A
></H2
><P
>   Germ&aacute;n M&eacute;ndez Bravo (Kronuz), 2004 - 2006
  </P
><P
>   This module was inspired by Garrett A. Wollman's
   <TT
CLASS="FILENAME"
>isbn_issn</TT
> code.
  </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="intarray.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="lo.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>intarray</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="contrib.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>lo</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>