1 /*-------------------------------------------------------------------------
4 * routines to support manipulation of the pg_largeobject relation
6 * Portions Copyright (c) 1996-2006, 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.25 2006/03/05 15:58:23 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 "miscadmin.h"
22 #include "utils/builtins.h"
23 #include "utils/fmgroids.h"
27 * Create a large object having the given LO identifier.
29 * We do this by inserting an empty first page, so that the object will
30 * appear to exist with size 0. Note that the unique index will reject
31 * an attempt to create a duplicate page.
34 LargeObjectCreate(Oid loid)
36 Relation pg_largeobject;
38 Datum values[Natts_pg_largeobject];
39 char nulls[Natts_pg_largeobject];
42 pg_largeobject = heap_open(LargeObjectRelationId, RowExclusiveLock);
47 for (i = 0; i < Natts_pg_largeobject; i++)
49 values[i] = (Datum) NULL;
54 values[i++] = ObjectIdGetDatum(loid);
55 values[i++] = Int32GetDatum(0);
56 values[i++] = DirectFunctionCall1(byteain,
59 ntup = heap_formtuple(pg_largeobject->rd_att, values, nulls);
64 simple_heap_insert(pg_largeobject, ntup);
67 CatalogUpdateIndexes(pg_largeobject, ntup);
69 heap_close(pg_largeobject, RowExclusiveLock);
75 LargeObjectDrop(Oid loid)
78 Relation pg_largeobject;
84 Anum_pg_largeobject_loid,
85 BTEqualStrategyNumber, F_OIDEQ,
86 ObjectIdGetDatum(loid));
88 pg_largeobject = heap_open(LargeObjectRelationId, RowExclusiveLock);
90 sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndexId, true,
91 SnapshotNow, 1, skey);
93 while ((tuple = systable_getnext(sd)) != NULL)
95 simple_heap_delete(pg_largeobject, &tuple->t_self);
101 heap_close(pg_largeobject, RowExclusiveLock);
105 (errcode(ERRCODE_UNDEFINED_OBJECT),
106 errmsg("large object %u does not exist", loid)));
110 LargeObjectExists(Oid loid)
113 Relation pg_largeobject;
118 * See if we can find any tuples belonging to the specified LO
120 ScanKeyInit(&skey[0],
121 Anum_pg_largeobject_loid,
122 BTEqualStrategyNumber, F_OIDEQ,
123 ObjectIdGetDatum(loid));
125 pg_largeobject = heap_open(LargeObjectRelationId, AccessShareLock);
127 sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndexId, true,
128 SnapshotNow, 1, skey);
130 if (systable_getnext(sd) != NULL)
133 systable_endscan(sd);
135 heap_close(pg_largeobject, AccessShareLock);