Questions tagged [nextval]

53 questions
48
votes
8 answers

PostgreSQL next value of the sequences?

I am using PostgreSQL for my Codeigniter website. I am using grocery crud for add, edit and delete operations. While doing an edit or add, I want to rename an uploaded file dynamically based on the id of the content. I am able to do this using…
i_nomad
  • 795
  • 2
  • 7
  • 9
34
votes
10 answers

get next sequence value from database using hibernate

I have an entity that has an NON-ID field that must be set from a sequence. Currently, I fetch for the first value of the sequence, store it on the client's side, and compute from that value. However, I'm looking for a "better" way of doing this. I…
iliaden
  • 3,791
  • 8
  • 38
  • 50
31
votes
5 answers

Select multiple ids from a PostgreSQL sequence

Is there a concise way to select the nextval for a PostgreSQL sequence multiple times in 1 query? This would be the only value being returned. For example, I would like to do something really short and sweet like: SELECT NEXTVAL('mytable_seq', 3)…
Mike Stone
  • 44,224
  • 30
  • 113
  • 140
8
votes
4 answers

How to get Oracle next sequence value in .NET Entity Framework?

I have a web api post method that inserts a new row in my table in my Oracle database. I'm having trouble with the primary key of the table which is a sequence value. How do I do my_primary_key_seq.nextval in Entity Framework? Currently this code…
iCanObjSeeSharp
  • 371
  • 2
  • 6
  • 13
7
votes
2 answers

Calling next value of a sequence in jpa

I have a class mapped as an Entity to persist it in a database. I have an id field as the primary key so every time the object is persisted the value of the id is retrieved from the sequence "myClass_pk_seq", a code like the following…
Javi
  • 19,387
  • 30
  • 102
  • 135
6
votes
5 answers

postgresql nextval generating existing values

I had to migrate from a mySql based ruby on rails app to using postgresql. No problems but one so far, and I don't know how to solve it. The migration of data brought ids along with it, and postgresql is now having problems with existing ids: it's…
Dan Donaldson
  • 317
  • 1
  • 4
  • 14
5
votes
0 answers

getting nextval for identity column

In my postgreSQL DB applications, I sometimes need to retrieve the next value of a sequence BEFORE running an insert. I used to make this by giving a “usage” privilege on such sequences to my users and using the “nextval” function. I recently begun…
Jacopo Russo
  • 103
  • 1
  • 4
4
votes
4 answers

How do I get the NextVal from an oracle Sequence thru NHibernate

I am working on c# .net 4.0 and using NHibernate to talk with an Oracle DB. You would think something as simple as this is already addressed somewhere but sadly its not. I need the NextVal from an Oracle sequence. I do not need to insert it a…
trainer
  • 369
  • 4
  • 14
4
votes
3 answers

rename sequence in other schema with same currval

I need to rename bunch of sequences in another schema. RENAME old_seq to new_seq doesnt work. Tried: ALTER SEQUENCE old_seq RENAME TO new_seq; but it gives me error ORA-02286: no options specified for ALTER SEQUENCE I do not wish to mention all…
Anu
  • 176
  • 1
  • 3
  • 14
3
votes
1 answer

Why in PostgreSQL when you delete a row in a table the id number of the future inserted row is not sequential?

I create the following table CREATE TABLE dogs ( id serial, name VARCHAR(15), age integer; I have the table looking like this Table "public.birds" Column | Type | …
buterfly85
  • 163
  • 3
  • 11
3
votes
2 answers

Retrieving CURRVAL and NEXTVAL in a single query

Using SQLPlus, I have the following sequence generated: CREATE SEQUENCE pubnum_seq START WITH 7 INCREMENT BY 2 MAXVALUE 1000; What I want to do is write a single query that retrieves both the NEXTVAL and the CURRVAL in the sequence. It seems…
tworley1977
  • 311
  • 2
  • 3
  • 12
2
votes
2 answers

Getting Invalid Identifier for Snowflake Sequence Nextval

I created a Sequence batch_id_seq in Snowflake. But when I am running the query "select batch_id_seq.nextval" from outside snowflake environment, I am getting the below error: SQL compilation error: error line 1 at position 7 invalid identifier…
user2238999
  • 121
  • 1
  • 1
  • 4
2
votes
3 answers

nextval and curval confusion in PostgreSQL

What will happen if multiple user run the following query at the same time? INSERT INTO…
nightfire001
  • 759
  • 3
  • 20
  • 50
2
votes
0 answers

Slow "nextval" calls

One of my service takes a long time to execute. Analysis has shown that nextval() calls of a certain sequence take about 5 seconds each. Why is that, and would you have suggestions to improve this? Thank you. Context This is a regular Spring 4.2.4 /…
Elegie
  • 340
  • 1
  • 5
  • 16
1
vote
1 answer

How to declare "nextval('testing_thing_thing_id_seq'::regclass)" as default value for column "thing_id" in postgres table "testing_thing"?

In my postgres db there is a table called testing_thing, which I can see (by running \d testing_thing in my psql prompt) it is defined as Table "public.testing_thing" Column | Type |…
Tms91
  • 3,456
  • 6
  • 40
  • 74
1
2 3 4