Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
cd2cf745
"...jdbc/org/postgresql/jdbc2/ResultSetMetaData.java" did not exist on "31a925c4d07675bc098a742ee9ca642ec79a40ee"
Commit
cd2cf745
authored
17 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Update sequence FAQ items, per suggestion from Pavel Stehule.
parent
81f285da
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/FAQ
+11
-20
11 additions, 20 deletions
doc/FAQ
doc/src/FAQ/FAQ.html
+15
-25
15 additions, 25 deletions
doc/src/FAQ/FAQ.html
with
26 additions
and
45 deletions
doc/FAQ
+
11
−
20
View file @
cd2cf745
Frequently Asked Questions (FAQ) for PostgreSQL
Last updated:
Mon
Oct
8 23:19:46
EDT 2007
Last updated:
Tue
Oct
9 15:52:10
EDT 2007
Current maintainer: Bruce Momjian (bruce@momjian.us)
...
...
@@ -697,28 +697,19 @@
name TEXT
);
See the create_sequence manual page for more information about
sequences.
Automatically created sequence are named <table>_<serialcolumn>_seq,
where table and serialcolumn are the names of the table and SERIAL
column, respectively. See the create_sequence manual page for more
information about sequences.
4.11.2) How do I get the value of a SERIAL insert?
One approach is to retrieve the next SERIAL value from the sequence
object with the nextval() function before inserting and then insert it
explicitly. Using the example table in 4.11.1, an example in a
pseudo-language would look like this:
new_id = execute("SELECT nextval('person_id_seq')");
execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')");
You would then also have the new value stored in new_id for use in
other queries (e.g., as a foreign key to the person table). Note that
the name of the automatically created SEQUENCE object will be named
<table>_< serialcolumn>_seq, where table and serialcolumn are the
names of your table and your SERIAL column, respectively.
Alternatively, you could retrieve the assigned SERIAL value with the
currval() function after it was inserted by default, e.g.,
execute("INSERT INTO person (name) VALUES ('Blaise Pascal')");
new_id = execute("SELECT currval('person_id_seq')");
The simplest way is to retrieve the assigned SERIAL value with
RETURNING. Using the example table in 4.11.1, it would look like this:
INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id;
You can also call nextval() and use that value in the INSERT, or call
currval() after the INSERT.
4.11.3) Doesn't currval() lead to a race condition with other users?
...
...
This diff is collapsed.
Click to expand it.
doc/src/FAQ/FAQ.html
+
15
−
25
View file @
cd2cf745
...
...
@@ -10,7 +10,7 @@
alink=
"#0000ff"
>
<H1>
Frequently Asked Questions (FAQ) for PostgreSQL
</H1>
<P>
Last updated:
Mon
Oct
8 23:19:46
EDT 2007
</P>
<P>
Last updated:
Tue
Oct
9 15:52:10
EDT 2007
</P>
<P>
Current maintainer: Bruce Momjian (
<A
href=
"mailto:bruce@momjian.us"
>
bruce@momjian.us
</A>
)
...
...
@@ -916,38 +916,28 @@ length</TD></TR>
);
</PRE>
See the
<I>
create_sequence
</I>
manual page for more information
about sequences.
<P>
Automatically created sequence are named
<
<I>
table
</I>
>
_
<
<I>
serialcolumn
</I>
>
_
<I>
seq
</I>
, where
<I>
table
</I>
and
<I>
serialcolumn
</I>
are the names of the table and
<SMALL>
SERIAL
</SMALL>
column, respectively. See the
<I>
create_sequence
</I>
manual page for more information about
sequences.
</P>
<H3
id=
"item4.11.2"
>
4.11.2) How do I get the value of a
<SMALL>
SERIAL
</SMALL>
insert?
</H3>
<P>
One approach is to retrieve the next
<SMALL>
SERIAL
</SMALL>
value
from the sequence object with the
<I>
nextval()
</I>
function
<I>
before
</I>
inserting and then insert it explicitly. Using the
example table in
<A
href=
"#item4.11.1"
>
4.11.1
</A>
, an example in a
pseudo-language would look like this:
</P>
<PRE>
new_id = execute("SELECT nextval('person_id_seq')");
execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')");
</PRE>
<P>
The simplest way is to retrieve the assigned
<SMALL>
SERIAL
</SMALL>
value with
<SMALL>
RETURNING
</SMALL>
. Using the example table in
<A
href=
"#item4.11.1"
>
4.11.1
</A>
, it would look like this:
</P>
You would then also have the new value stored in
<CODE>
new_id
</CODE>
for use in other queries (e.g., as a foreign key to the
<CODE>
person
</CODE>
table). Note that the name of the automatically created
<SMALL>
SEQUENCE
</SMALL>
object will be named
<
<I>
table
</I>
>
_
<
<I>
serialcolumn
</I>
>
_
<I>
seq
</I>
, where
<I>
table
</I>
and
<I>
serialcolumn
</I>
are the names of your table and your
<SMALL>
SERIAL
</SMALL>
column,
respectively.
<P>
Alternatively, you could retrieve the assigned
<SMALL>
SERIAL
</SMALL>
value with the
<I>
currval()
</I>
function
<I>
after
</I>
it was inserted by
default, e.g.,
</P>
<PRE>
execute("INSERT INTO person (name) VALUES ('Blaise Pascal')");
new_id = execute("SELECT currval('person_id_seq')");
INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id;
</PRE>
You can also call
<I>
nextval()
</I>
and use that value in the
<SMALL>
INSERT
</SMALL>
, or call
<I>
currval()
</I>
<I>
after
</I>
the
<SMALL>
INSERT
</SMALL>
.
<H3
id=
"item4.11.3"
>
4.11.3) Doesn't
<I>
currval()
</I>
lead to a race condition with other users?
</H3>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment