<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> Practical PostgreSQL</title> <meta name="keywords" content="postgresql, support, recovery, design, software, hosting, expterise, programming, postgres, pgsql, replication, mysql, firebird, database, sql, free, open source, software" /> <meta name="description" content="Command Prompt, Inc. is the largest and oldest US based commercial PostgreSQL support provider. We provide the only commercially viable integrated PostgreSQL replication solution, but also custom programming, and support. We authored the book Practical PostgreSQL, the procedural language plPHP, and adding trigger capability to plPerl. " /> <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" /> <link rel="stylesheet" type="text/css" href="../css/layout.css" /> <link rel="stylesheet" type="text/css" href="../css/cmd4.css" /> <script language="javascript" type="text/javascript"><!-- greymenuhomewideLit = new Image(); greymenuhomewideLit.src = "/images/greymenu_homewide_lit.gif"; greymenuaboutLit = new Image(); greymenuaboutLit.src = "/images/greymenu_about_lit.gif"; greymenuproductsLit = new Image(); greymenuproductsLit.src = "/images/greymenu_products_lit.gif"; greymenuservicesLit = new Image(); greymenuservicesLit.src = "/images/greymenu_services_lit.gif"; greymenusupportLit = new Image(); greymenusupportLit.src = "/images/greymenu_support_lit.gif"; greymenucommunityLit = new Image(); greymenucommunityLit.src = "/images/greymenu_community_lit.gif"; //--></script> </head> <body> <div align="center"> <div id="widecontainer"> <div id="widetop"> <div class="throwleft" style="width: 300px; text-align: left;"><a href="http://www.commandprompt.com/"><img src="../images/cmd4logo_wide.gif" border="0" alt="Command Prompt, Inc." /></a></div> <div class="throwright" style="width: 400px; text-align: right;"> <div id="topright"> <form action="index.html" name="cmdform" method="post"> <ul> <li><input type="text" name="search" value="" /></li> <li><input type="submit" name="action" value="Search Book" /></li> </ul> </form> </div> </div> </div> <ul id="greymenu_wide"> <li><a href="http://www.commandprompt.com/home/"><img onmouseover="this.src = greymenuhomewideLit.src;" onmouseout="this.src = '/images/greymenu_homewide.gif';" src="../images/greymenu_homewide.gif" border="0" height="22" title="" alt="" /></a></li><li><img src="../images/greymenu_divider.gif" border="0" width="2" height="22" alt="|" /></li><li><a href="http://www.commandprompt.com/about/"><img onmouseover="this.src = greymenuaboutLit.src;" onmouseout="this.src = '/images/greymenu_about.gif';" src="../images/greymenu_about.gif" border="0" height="22" title="" alt="" /></a></li><li><img src="../images/greymenu_divider.gif" border="0" width="2" height="22" alt="|" /></li><li><a href="http://www.commandprompt.com/products/"><img onmouseover="this.src = greymenuproductsLit.src;" onmouseout="this.src = '/images/greymenu_products.gif';" src="../images/greymenu_products.gif" border="0" height="22" title="" alt="" /></a></li><li><img src="../images/greymenu_divider.gif" border="0" width="2" height="22" alt="|" /></li><li><a href="http://www.commandprompt.com/services/"><img onmouseover="this.src = greymenuservicesLit.src;" onmouseout="this.src = '/images/greymenu_services.gif';" src="../images/greymenu_services.gif" border="0" height="22" title="" alt="" /></a></li><li><img src="../images/greymenu_divider.gif" border="0" width="2" height="22" alt="|" /></li><li><a href="http://www.commandprompt.com/support/"><img onmouseover="this.src = greymenusupportLit.src;" onmouseout="this.src = '/images/greymenu_support.gif';" src="../images/greymenu_support.gif" border="0" height="22" title="" alt="" /></a></li><li><img src="../images/greymenu_divider.gif" border="0" width="2" height="22" alt="|" /></li><li><a href="http://www.commandprompt.com/community/"><img onmouseover="this.src = greymenucommunityLit.src;" onmouseout="this.src = '/images/greymenu_community.gif';" src="../images/greymenu_community.gif" border="0" height="22" title="" alt="" /></a></li> </ul> <div style="padding-left: 16px; width: 96%;"> <HTML ><HEAD ><TITLE >Tuples</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.72 "><LINK REL="HOME" TITLE="Practical PostgreSQL" href="book1"><LINK REL="UP" TITLE="Binary COPY Format" href="a29525"><LINK REL="PREVIOUS" TITLE="Binary COPY Format" href="a29525"><LINK REL="NEXT" TITLE="Trailer" href="x29593"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Practical PostgreSQL</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A href="a29525" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Appendix C. Binary COPY Format</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A href="x29593" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="AEN29561" >Tuples</A ></H1 ><P >The structure of tuples within the binary file is as follows: a 16-bit integer count of the fields within the tuple (this is the same within every tuple), a 16-bit integer <SPAN ><I CLASS="EMPHASIS" >typlen</I ></SPAN > word, and the field data for each field. The available options for the <SPAN ><I CLASS="EMPHASIS" >typlen</I ></SPAN > field are as follow: <P ></P ><DIV CLASS="VARIABLELIST" ><DL ><DT >0</DT ><DD ><P ><TT CLASS="COMPUTEROUTPUT" >NULL</TT >; this field contains no data.</P ></DD ><DT >>0</DT ><DD ><P >A fixed-length data type. The specified number bytes of data follow the <SPAN ><I CLASS="EMPHASIS" >typlen</I ></SPAN > word.</P ></DD ><DT >-1</DT ><DD ><P >A <SPAN ><I CLASS="EMPHASIS" >varlena</I ></SPAN > data type. The next four bytes are the <SPAN ><I CLASS="EMPHASIS" >varlena</I ></SPAN > header, consisting of the value's total length (including the length of the header).</P ></DD ><DT ><-1</DT ><DD ><P >Reserved for possible future use.</P ></DD ></DL ></DIV > </P ><P >To create a convenient way for an application reading this format to check the integrity of incoming binary data, all non-<TT CLASS="COMPUTEROUTPUT" >NULL</TT > fields have a <SPAN ><I CLASS="EMPHASIS" >typlen</I ></SPAN > value, which can be compared against the <SPAN ><I CLASS="EMPHASIS" >typlen</I ></SPAN > of the destination column before attempting to insert or update data within PostgreSQL.</P ><P >A few formatting options were left un-implemented to improve the portability of binary file dumps. Primarily, extra data between fields is not possible (e.g., alignment padding), and there is no distinguishment between data types based on passes by reference, or passes by value.</P ><P >If OIDs are included in a PostgreSQL binary file, they immediately follow the field count word. OIDs are not included in the field count.</P ></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="a29525" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A href="book1" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A href="x29593" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Binary COPY Format</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A href="a29525" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Trailer</TD ></TR ></TABLE ></DIV ></BODY ></HTML > </div> <br /> <div id="thefineprint"> <a href="http://www.commandprompt.com/products/mammothpostgresql/"><img src="../images/powered_by_mammoth.gif" alt="Powered by Mammoth PostgreSQL" title="Powered by Mammoth PostgreSQL" border="0" /></a> <br /> Copyright © 2000-2007 Command Prompt, Inc. All Rights Reserved. All trademarks property of their respective owners. </div> </div> </div> </body> </html>