Properly mark pg_freespace() function as strict. Also update
[PostgreSQL.git] / contrib / pg_freespacemap / pg_freespacemap.c
blobcb6e4bb16750f01ac0af288a92d1a90c09b85c65
1 /*-------------------------------------------------------------------------
3 * pg_freespacemap.c
4 * display contents of a free space map
6 * $PostgreSQL$
7 *-------------------------------------------------------------------------
8 */
9 #include "postgres.h"
11 #include "access/heapam.h"
12 #include "funcapi.h"
13 #include "storage/block.h"
14 #include "storage/freespace.h"
17 PG_MODULE_MAGIC;
19 Datum pg_freespace(PG_FUNCTION_ARGS);
22 * Returns the amount of free space on a given page, according to the
23 * free space map.
25 PG_FUNCTION_INFO_V1(pg_freespace);
27 Datum
28 pg_freespace(PG_FUNCTION_ARGS)
30 Oid relid = PG_GETARG_OID(0);
31 int64 blkno = PG_GETARG_INT64(1);
32 int16 freespace;
33 Relation rel;
35 rel = relation_open(relid, AccessShareLock);
37 if (blkno < 0 || blkno > MaxBlockNumber)
38 ereport(ERROR,
39 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
40 errmsg("invalid block number")));
42 freespace = GetRecordedFreeSpace(rel, blkno);
44 relation_close(rel, AccessShareLock);
45 PG_RETURN_INT16(freespace);