1 /*-------------------------------------------------------------------------
4 * routines to support manipulation of the pg_largeobject relation
6 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/catalog/pg_largeobject.c,v 1.27 2007/01/05 22:19:25 momjian Exp $
13 *-------------------------------------------------------------------------
17 #include "access/genam.h"
18 #include "access/heapam.h"
19 #include "catalog/indexing.h"
20 #include "catalog/pg_largeobject.h"
21 #include "utils/builtins.h"
22 #include "utils/fmgroids.h"
26 * Create a large object having the given LO identifier.
28 * We do this by inserting an empty first page, so that the object will
29 * appear to exist with size 0. Note that the unique index will reject
30 * an attempt to create a duplicate page.
33 LargeObjectCreate(Oid loid)
35 Relation pg_largeobject;
37 Datum values[Natts_pg_largeobject];
38 char nulls[Natts_pg_largeobject];
41 pg_largeobject = heap_open(LargeObjectRelationId, RowExclusiveLock);
46 for (i = 0; i < Natts_pg_largeobject; i++)
48 values[i] = (Datum) NULL;
53 values[i++] = ObjectIdGetDatum(loid);
54 values[i++] = Int32GetDatum(0);
55 values[i++] = DirectFunctionCall1(byteain,
58 ntup = heap_formtuple(pg_largeobject->rd_att, values, nulls);
63 simple_heap_insert(pg_largeobject, ntup);
66 CatalogUpdateIndexes(pg_largeobject, ntup);
68 heap_close(pg_largeobject, RowExclusiveLock);
74 LargeObjectDrop(Oid loid)
77 Relation pg_largeobject;
83 Anum_pg_largeobject_loid,
84 BTEqualStrategyNumber, F_OIDEQ,
85 ObjectIdGetDatum(loid));
87 pg_largeobject = heap_open(LargeObjectRelationId, RowExclusiveLock);
89 sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndexId, true,
90 SnapshotNow, 1, skey);
92 while ((tuple = systable_getnext(sd)) != NULL)
94 simple_heap_delete(pg_largeobject, &tuple->t_self);
100 heap_close(pg_largeobject, RowExclusiveLock);
104 (errcode(ERRCODE_UNDEFINED_OBJECT),
105 errmsg("large object %u does not exist", loid)));
109 LargeObjectExists(Oid loid)
112 Relation pg_largeobject;
117 * See if we can find any tuples belonging to the specified LO
119 ScanKeyInit(&skey[0],
120 Anum_pg_largeobject_loid,
121 BTEqualStrategyNumber, F_OIDEQ,
122 ObjectIdGetDatum(loid));
124 pg_largeobject = heap_open(LargeObjectRelationId, AccessShareLock);
126 sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndexId, true,
127 SnapshotNow, 1, skey);
129 if (systable_getnext(sd) != NULL)
132 systable_endscan(sd);
134 heap_close(pg_largeobject, AccessShareLock);