Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 502E79FB768 for ; Fri, 17 Aug 2007 18:50:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 24159-10 for ; Fri, 17 Aug 2007 18:49:48 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.189]) by postgresql.org (Postfix) with ESMTP id E2B589FA0C3 for ; Fri, 17 Aug 2007 18:50:01 -0300 (ADT) Received: by rv-out-0910.google.com with SMTP id l15so521861rvb for ; Fri, 17 Aug 2007 14:50:00 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=tTe5EgndchIECf9Nevt2Nrn8E3A46vA13sSg1ph3yFUQ+eiq7cp1RLoN/SEk9hL8J1f9Tjx0BHKwbV48bRNk6xjlzWX+tU7mGy5C+ArVzadHbvAzIart3IjibBZpkL1fptNRmhtnrXhYwMFG4Ynstxwe1zAl9OijVCweMWfFTKM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=emSbKdK4rLYrcJWsB1RTk3xvF88/DHAlfeoVOoIYSGKNdVmmobZ0GHWyhSGzuU7OmM+vJYvI9jOHvULHBjXPkkoX5QL4+KBZKwbNSuDhTAVwg64opdGt+h8LWJc4FU6cTl6sZr/ZbrbZZQOuo7Qg2kV4BJLUYE0wmJ9J07oatuc= Received: by 10.141.28.12 with SMTP id f12mr1447087rvj.1187387400121; Fri, 17 Aug 2007 14:50:00 -0700 (PDT) Received: by 10.141.98.12 with HTTP; Fri, 17 Aug 2007 14:50:00 -0700 (PDT) Message-ID: Date: Fri, 17 Aug 2007 16:50:00 -0500 From: "Scott Marlowe" To: Judith Subject: Re: Sequences problem Cc: pgsql-sql@postgresql.org In-Reply-To: <46C61410.4070407@correolux.com.mx> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46C61410.4070407@correolux.com.mx> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/150 X-Sequence-Number: 29088 On 8/17/07, Judith wrote: > Hello everybody, I have a question related with sequences............. > > When I init a sesion with my db, if a do the next sentence: > > SELECT currval('pagos_id_pago_seq'); > > > return this: > ERROR: the relation doesn't exist > (or somethimg like that, because the message is in spanish) > > but if I do first, > > SELECT nextval('pagos_id_pago_seq'); > > and then > SELECT currval('pagos_id_pago_seq'); it success, returns the > current sequence value, it is possible to indicate that the sequence is > already started and in the value 4567 but I need first to now the > current value before the next, how can I do? Sorry, that's not how sequences work. Have you read the manual on sequence manipulation? http://www.postgresql.org/docs/8.2/static/functions-sequence.html Sequences are designed to allow fast access to sequentially increasing numbers to use as identifiers in the database. While they guarantee no repeats (unless you set them to roll over etc...) they don't guarantee no gaps. so, the current value only has context if you've actually pulled a sequence from the generator, otherwise what it is right now isn't really important yet. There are some functions you can use to get the current number, but doing that is not safe from race conditions, so you should only do that stuff while access to the db is shut off to other users.