RefLib

Reference library for AI

Back

postgresql_16:5.2.3.9 Truncating a Large Object

PostgreSQL 16 > Client Interfaces > Large Objects > Client Interfaces > Truncating a Large Object

To truncate a large object to a given length, call int lo_truncate(PGconn *conn, int fd, size_t len); This function truncates the large object descriptor fd to length len. The fd argument must have been returned by a previous lo_open. If len is greater than the large object's current length, the large object is extended to the specified length with null bytes ('\0'). On success, lo_truncate returns zero. On error, the return value is -1.

The read/write location associated with the descriptor fd is not changed.

Although the len parameter is declared as size_t, lo_truncate will reject length values larger than INT_MAX.

When dealing with large objects that might exceed 2GB in size, instead use int lo_truncate64(PGconn *conn, int fd, pg_int64 len); This function has the same behavior as lo_truncate, but it can accept a len value exceeding 2GB.

lo_truncate is new as of PostgreSQL 8.3; if this function is run against an older server version, it will fail and return -1.

lo_truncate64 is new as of PostgreSQL 9.3; if this function is run against an older server version, it will fail and return -1.

Back