1 /*-------------------------------------------------------------------------
4 * Generic routines for sequence-related code.
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/access/sequence/sequence.c
15 * This file contains sequence_ routines that implement access to sequences
16 * (in contrast to other relation types like indexes).
18 *-------------------------------------------------------------------------
23 #include "access/relation.h"
24 #include "access/sequence.h"
25 #include "storage/lmgr.h"
27 static inline void validate_relation_kind(Relation r
);
30 * sequence_open - open a sequence relation by relation OID
32 * This is essentially relation_open plus check that the relation
37 sequence_open(Oid relationId
, LOCKMODE lockmode
)
41 r
= relation_open(relationId
, lockmode
);
43 validate_relation_kind(r
);
49 * sequence_close - close a sequence
51 * If lockmode is not "NoLock", we then release the specified lock.
53 * Note that it is often sensible to hold a lock beyond relation_close;
54 * in that case, the lock is released automatically at xact end.
58 sequence_close(Relation relation
, LOCKMODE lockmode
)
60 relation_close(relation
, lockmode
);
64 * validate_relation_kind - check the relation's kind
66 * Make sure relkind is from a sequence.
70 validate_relation_kind(Relation r
)
72 if (r
->rd_rel
->relkind
!= RELKIND_SEQUENCE
)
74 (errcode(ERRCODE_WRONG_OBJECT_TYPE
),
75 errmsg("cannot open relation \"%s\"",
76 RelationGetRelationName(r
)),
77 errdetail_relkind_not_supported(r
->rd_rel
->relkind
)));