1 /*-------------------------------------------------------------------------
4 * routines to support manipulation of the pg_largeobject relation
6 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.15 2003/07/21 01:59:10 tgl Exp $
13 *-------------------------------------------------------------------------
17 #include "access/genam.h"
18 #include "access/heapam.h"
19 #include "catalog/catname.h"
20 #include "catalog/indexing.h"
21 #include "catalog/pg_largeobject.h"
22 #include "miscadmin.h"
23 #include "utils/builtins.h"
24 #include "utils/fmgroids.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 char nulls[Natts_pg_largeobject];
43 pg_largeobject = heap_openr(LargeObjectRelationName, 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_formtuple(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 ScanKeyEntryInitialize(&skey[0],
88 (RegProcedure) F_OIDEQ,
89 ObjectIdGetDatum(loid));
91 pg_largeobject = heap_openr(LargeObjectRelationName, RowShareLock);
92 pg_lo_idx = index_openr(LargeObjectLOidPNIndex);
94 sd = index_beginscan(pg_largeobject, pg_lo_idx, SnapshotNow, 1, skey);
96 while ((tuple = index_getnext(sd, ForwardScanDirection)) != NULL)
98 simple_heap_delete(pg_largeobject, &tuple->t_self);
104 index_close(pg_lo_idx);
105 heap_close(pg_largeobject, RowShareLock);
109 (errcode(ERRCODE_UNDEFINED_OBJECT),
110 errmsg("large object %u does not exist", loid)));
114 LargeObjectExists(Oid loid)
117 Relation pg_largeobject;
124 * See if we can find any tuples belonging to the specified LO
126 ScanKeyEntryInitialize(&skey[0],
129 (RegProcedure) F_OIDEQ,
130 ObjectIdGetDatum(loid));
132 pg_largeobject = heap_openr(LargeObjectRelationName, RowShareLock);
133 pg_lo_idx = index_openr(LargeObjectLOidPNIndex);
135 sd = index_beginscan(pg_largeobject, pg_lo_idx, SnapshotNow, 1, skey);
137 if ((tuple = index_getnext(sd, ForwardScanDirection)) != NULL)
142 index_close(pg_lo_idx);
143 heap_close(pg_largeobject, RowShareLock);