Created
February 28, 2014 23:05
-
-
Save xivSolutions/9281856 to your computer and use it in GitHub Desktop.
currval() Issue in PG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A table, "turtles": | |
CREATE TABLE turtles | |
( | |
id serial NOT NULL, | |
name text, | |
lastid integer, | |
CONSTRAINT pk_turtles PRIMARY KEY (id) | |
) | |
WITH ( | |
OIDS=FALSE | |
); | |
ALTER TABLE turtles | |
OWNER TO john; | |
-- INSERT, say, 2103 records. | |
-- then take curval: | |
SELECT currval('turtles_id_seq') as newId; | |
-- returns 2103. Then clear the table: | |
DELETE FROM turtles | |
-- Close the session. Come back tomorrow, try curval: | |
SELECT currval('turtles_id_seq') as newId; | |
-- Get this: | |
ERROR: currval of sequence "turtles_id_seq" is not yet defined in this session | |
SQL state: 55000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment