1 /*-------------------------------------------------------------------------
4 * routines to support manipulation of the pg_largeobject relation
6 * Portions Copyright (c) 1996-2008, 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.31 2008/11/02 01:45:27 tgl 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"
23 #include "utils/rel.h"
24 #include "utils/tqual.h"
28 * Create a large object having the given LO identifier.
30 * We do this by inserting an empty first page, so that the object will
31 * appear to exist with size 0. Note that the unique index will reject
32 * an attempt to create a duplicate page.
35 LargeObjectCreate(Oid loid)
37 Relation pg_largeobject;
39 Datum values[Natts_pg_largeobject];
40 bool nulls[Natts_pg_largeobject];
43 pg_largeobject = heap_open(LargeObjectRelationId, RowExclusiveLock);
48 for (i = 0; i < Natts_pg_largeobject; i++)
50 values[i] = (Datum) NULL;
55 values[i++] = ObjectIdGetDatum(loid);
56 values[i++] = Int32GetDatum(0);
57 values[i++] = DirectFunctionCall1(byteain,
60 ntup = heap_form_tuple(pg_largeobject->rd_att, values, nulls);
65 simple_heap_insert(pg_largeobject, ntup);
68 CatalogUpdateIndexes(pg_largeobject, ntup);
70 heap_close(pg_largeobject, RowExclusiveLock);
76 LargeObjectDrop(Oid loid)
79 Relation pg_largeobject;
85 Anum_pg_largeobject_loid,
86 BTEqualStrategyNumber, F_OIDEQ,
87 ObjectIdGetDatum(loid));
89 pg_largeobject = heap_open(LargeObjectRelationId, RowExclusiveLock);
91 sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndexId, true,
92 SnapshotNow, 1, skey);
94 while ((tuple = systable_getnext(sd)) != NULL)
96 simple_heap_delete(pg_largeobject, &tuple->t_self);
100 systable_endscan(sd);
102 heap_close(pg_largeobject, RowExclusiveLock);
106 (errcode(ERRCODE_UNDEFINED_OBJECT),
107 errmsg("large object %u does not exist", loid)));
111 LargeObjectExists(Oid loid)
114 Relation pg_largeobject;
119 * See if we can find any tuples belonging to the specified LO
121 ScanKeyInit(&skey[0],
122 Anum_pg_largeobject_loid,
123 BTEqualStrategyNumber, F_OIDEQ,
124 ObjectIdGetDatum(loid));
126 pg_largeobject = heap_open(LargeObjectRelationId, AccessShareLock);
128 sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndexId, true,
129 SnapshotNow, 1, skey);
131 if (systable_getnext(sd) != NULL)
134 systable_endscan(sd);
136 heap_close(pg_largeobject, AccessShareLock);