Skip to Main Content
Practical PostgreSQL
book

Practical PostgreSQL

by Joshua D. Drake, John C. Worsley
January 2002
Intermediate to advanced content levelIntermediate to advanced
640 pages
16h 39m
English
O'Reilly Media, Inc.
Content preview from Practical PostgreSQL

Tuples

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 typlen word, and the field data for each field. The available options for the typlen field are as follow:

0

NULL; this field contains no data.

>0

A fixed-length data type. The specified number bytes of data follow the typlen word.

-1

A varlena data type. The next four bytes are the varlena header, consisting of the value’s total length (including the length of the header).

<-1

Reserved for possible future use.

To create a convenient way for an application reading this format to check the integrity of incoming binary data, all non-NULL fields have a typlen value, which can be compared against the typlen of the destination column before attempting to insert or update data within PostgreSQL.

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.

If OIDs are included in a PostgreSQL binary file, they immediately follow the field count word. OIDs are not included in the field count.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PostgreSQL: Up and Running, 2nd Edition

PostgreSQL: Up and Running, 2nd Edition

Regina O. Obe, Leo S. Hsu
Learning PostgreSQL 11 - Third Edition

Learning PostgreSQL 11 - Third Edition

Christopher Travers, Andrey Volkov
Learn PostgreSQL

Learn PostgreSQL

Luca Ferrari, Enrico Pirozzi
PostgreSQL 13 Cookbook

PostgreSQL 13 Cookbook

Vallarapu Naga Avinash Kumar

Publisher Resources

ISBN: 9781449309770Supplemental ContentErrata Page