nextval

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) AS id; And get: id ----- 118 119 120 (3 rows) ...

serial type produce only even or odd numbers in postgresql

I want set some constraint to the serial type,it only produce even or odd numbers. ...

nextval sequence for varchar in sql?

HI there, i was wondering if there was a way of making a nextval sequence for a varchar value? I am using iSQL plus, oracle. For e.g. I have a sales table which consists of sale_id, prod_id, cust_name, sale_name. where i insert the data by doing the following: insert into sales select sale_id_seq.nextval, trunc(dbms_random.value(1,100))...

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 not clear to me where it gets the value that it uses to determine the base for nextval: i...

postgresql nextval question on sequences

Hi, I am trying to work with postgresql 'nextval' in PHP. How can I fill in the parenthesis in the third line in order to replace TXN_ID with the value of nextval('schemadb.audit_txn_seq')? $DB->query("SELECT nextval('schemadb.audit_txn_seq')"); $DB->query('SET CONSTRAINTS ALL DEFERRED'); $DB->query('SELECT schemadb.undo_transaction(TX...

Calling next value of a sequence in jpa

Hello, 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 one. @Entity @Table(name="myObjects") public class MyClass { @Id @GeneratedValue(strate...