12.1. Working with PostgreSQL BLOBs Using SQL

The first topic in this chapter is PostgreSQL's SQL interface to BLOBs. PostgreSQL provides a set of easy-to-use functions for working with BLOBs. Using these functions is not difficult because most of these functions are only SQL counterparts of widely used C functions.

First of all, a BLOB is not stored in a table but as an object in the database. A BLOB must be accessed via a so-called object id, which is a unique identifier of an object in a database. The object id of a BLOB can then be stored in a table so that it does not get lost in the database.

Let's create a table for storing object ids and a description of the files the object id is pointing to:

phpbook=# CREATE TABLE ext4(file_oid oid, ...

Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.