Debian Codegraph @

docs/bdb-sql/sequencesupport.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Using Sequences</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Getting Started with the Oracle Berkeley DB SQL APIs" />
10 <link rel="up" href="dbsqlbasics.html" title="Chapter 1. Berkeley DB SQL: The Absolute Basics" />
11 <link rel="prev" href="sql_encryption.html" title="Encryption" />
12 <link rel="next" href="normal-sql.html" title="Differences for Users of other SQL Engines" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Using Sequences</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="sql_encryption.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 1. Berkeley DB SQL: The Absolute Basics</th>
26 <td width="20%" align="right"> <a accesskey="n" href="normal-sql.html">Next</a></td>
27 </tr>
28 </table>
29 <hr />
30 </div>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
33 <div>
34 <div>
35 <h2 class="title" style="clear: both"><a id="sequencesupport"></a>Using Sequences</h2>
36 </div>
37 </div>
38 </div>
39 <div class="toc">
40 <dl>
41 <dt>
42 <span class="sect2">
43 <a href="sequencesupport.html#create_sequence">create_sequence</a>
44 </span>
45 </dt>
46 <dt>
47 <span class="sect2">
48 <a href="sequencesupport.html#seq_nextval">nextval</a>
49 </span>
50 </dt>
51 <dt>
52 <span class="sect2">
53 <a href="sequencesupport.html#seq_currval">currval</a>
54 </span>
55 </dt>
56 <dt>
57 <span class="sect2">
58 <a href="sequencesupport.html#seq_drop_sequence">drop_sequence</a>
59 </span>
60 </dt>
61 </dl>
62 </div>
63 <p>
64 You can use sequences with the SQL API.
65 Sequences provide for an arbitrary number of increasing or
66 decreasing integers that persist across database accesses.
67 Use sequences if you need to create unique values in a
68 highly efficient and persistent way.
69 </p>
70 <p>
71 To create and access a sequence, you must use SQL
72 functionality that is unique to the BDB SQL interface; no
73 corresponding functionality exists in SQLite. The
74 sequence functionality is implemented using SQLite
75 function plugins, as such it is necessary to use the
76 'select' keyword as a prefix to all sequence APIs.
77 </p>
78 <p>
79 The SQL API sequence support is a partial implementation of
80 the sequence API defined in the SQL 2003 specification.
81 </p>
82 <p>
83 The following sections describe the BDB SQL interface sequence API.
84 </p>
85 <div class="sect2" lang="en" xml:lang="en">
86 <div class="titlepage">
87 <div>
88 <div>
89 <h3 class="title"><a id="create_sequence"></a>create_sequence</h3>
90 </div>
91 </div>
92 </div>
93 <p>
94 Creates a new sequence. A name is required, all other
95 parameters are optional. For example:
96 </p>
97 <pre class="programlisting">SELECT create_sequence("my_sequence", "start", 100, "incr", 10,
98 "maxvalue", 300);</pre>
99 <p>
100 This creates a sequence called <code class="literal">my_sequence</code>
101 starting at 100 and incrementing by 10 until it reaches
102 300.
103 </p>
104 <pre class="programlisting">SELECT create_sequence("my_decr_sequence", "incr", -100,
105 "minvalue", -10000);</pre>
106 <p>
107 This creates a sequence call <code class="literal">my_decr_sequence</code>
108 starting at 0 and decreasing by 100 until it reaches
109 -10000.
110 </p>
111 <p>
112 Parameters are:
113 </p>
114 <div class="itemizedlist">
115 <ul type="disc">
116 <li>
117 <p>
118 <code class="literal">name</code>
119 </p>
120 <p>
121 Required parameter that provides the name of
122 the sequence. It is an error to create a
123 sequence with another name that is currently in
124 use within the database.
125 </p>
126 </li>
127 <li>
128 <p>
129 <code class="literal">start</code>
130 </p>
131 <p>
132 The starting value for the sequence. If this
133 parameter is not provided then
134 <code class="literal">0</code> is used.
135 </p>
136 </li>
137 <li>
138 <p>
139 <code class="literal">minvalue</code>
140 </p>
141 <p>
142 The lowest value generated by the sequence. If
143 this parameter is not provided and a
144 decrementing sequence is created, then
145 INT64_MIN is used.
146 </p>
147 </li>
148 <li>
149 <p>
150 <code class="literal">maxvalue</code>
151 </p>
152 <p>
153 The largest value generated by the sequence.
154 If this parameter is not provided and an
155 incrementing sequence is created, then
156 INT64_MAX is used.
157 </p>
158 </li>
159 <li>
160 <p>
161 <code class="literal">incr</code>
162 </p>
163 <p>
164 The amount the sequence is incremented for each
165 get operation. This value can be positive or
166 negative. If this parameter is not provided,
167 then <code class="literal">1</code> is used.
168 </p>
169 </li>
170 <li>
171 <p>
172 <code class="literal">cache</code>
173 </p>
174 <p>
175 Causes each handle to keep a cache of sequence
176 values. So long as there are values available
177 in the cache, retrieving the next value is
178 cheap and does not lead to contention between
179 handles.
180 </p>
181 <p>
182 Sequences with caches cannot be created or dropped
183 within an explicit transaction.
184 </p>
185 <p>
186 Operations on caching sequences are not
187 transactionally protected. That is, a rollback
188 will not result in a value being returned to
189 the sequence.
190 </p>
191 <p>
192 Sequences with caches do not support the
193 <code class="literal">currval</code> function.
194 </p>
195 <p>
196 The parameter following the cache parameter must be
197 an integer value specifying the size of the cache.
198 </p>
199 </li>
200 </ul>
201 </div>
202 </div>
203 <div class="sect2" lang="en" xml:lang="en">
204 <div class="titlepage">
205 <div>
206 <div>
207 <h3 class="title"><a id="seq_nextval"></a>nextval</h3>
208 </div>
209 </div>
210 </div>
211 <p>
212 Retrieves the next value from the named sequence. For
213 example:
214 </p>
215 <pre class="programlisting">SELECT nextval("my_sequence");</pre>
216 </div>
217 <div class="sect2" lang="en" xml:lang="en">
218 <div class="titlepage">
219 <div>
220 <div>
221 <h3 class="title"><a id="seq_currval"></a>currval</h3>
222 </div>
223 </div>
224 </div>
225 <p>
226 Retrieves the last value that was returned from the
227 named sequence. For example:
228 </p>
229 <pre class="programlisting">SELECT currval("my_sequence");</pre>
230 </div>
231 <div class="sect2" lang="en" xml:lang="en">
232 <div class="titlepage">
233 <div>
234 <div>
235 <h3 class="title"><a id="seq_drop_sequence"></a>drop_sequence</h3>
236 </div>
237 </div>
238 </div>
239 <p>
240 Removes the sequence. For example:
241 </p>
242 <pre class="programlisting">SELECT drop_sequence("my_sequence");</pre>
243 </div>
244 </div>
245 <div class="navfooter">
246 <hr />
247 <table width="100%" summary="Navigation footer">
248 <tr>
249 <td width="40%" align="left"><a accesskey="p" href="sql_encryption.html">Prev</a> </td>
250 <td width="20%" align="center">
251 <a accesskey="u" href="dbsqlbasics.html">Up</a>
252 </td>
253 <td width="40%" align="right"> <a accesskey="n" href="normal-sql.html">Next</a></td>
254 </tr>
255 <tr>
256 <td width="40%" align="left" valign="top">Encryption </td>
257 <td width="20%" align="center">
258 <a accesskey="h" href="index.html">Home</a>
259 </td>
260 <td width="40%" align="right" valign="top"> Differences for Users of other SQL Engines</td>
261 </tr>
262 </table>
263 </div>
264 </body>
265 </html>