X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4BC8752A26 for ; Sat, 9 Jul 2005 22:00:46 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57890-06 for ; Sun, 10 Jul 2005 01:00:36 +0000 (GMT) Received: from priv-edtnes56.telusplanet.net (outbound01.telus.net [199.185.220.220]) by svr1.postgresql.org (Postfix) with ESMTP id D15AE52B03 for ; Sat, 9 Jul 2005 22:00:32 -0300 (ADT) Received: from localhost ([199.185.220.240]) by priv-edtnes56.telusplanet.net (InterMail vM.6.01.04.04 201-2131-118-104-20050224) with ESMTP id <20050710010036.HCE24768.priv-edtnes56.telusplanet.net@localhost>; Sat, 9 Jul 2005 19:00:36 -0600 Received: from 64.180.246.130 ( [64.180.246.130]) as user a3a18850@192.168.200.1 by webmail.telus.net with HTTP; Sat, 9 Jul 2005 18:00:36 -0700 Message-ID: <1120957236.42d07334209cd@webmail.telus.net> Date: Sat, 9 Jul 2005 18:00:36 -0700 From: Mischa Sandberg To: "jimmy.olsen" Cc: pgsql-sql@postgresql.org Subject: Re: getting back autonumber just inserted References: <42CD6B58.6060508@techevolution.be> <20050707180329.GA11332@alvh.no-ip.org> <007901c58486$5a973430$230a0a0a@ligaone.com.br> In-Reply-To: <007901c58486$5a973430$230a0a0a@ligaone.com.br> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.1-cvs X-Originating-IP: 64.180.246.130 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.06 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_POST, FORGED_RCVD_HELO X-Spam-Level: * X-Archive-Number: 200507/94 X-Sequence-Number: 22072 Quoting "jimmy.olsen" : > I don't know how to create a Global Variable in Postgres, but the > idea is > very simple: > 1. Encapsulate the NextVal function in MyNextVal > 2. Set to Global variable with NextVal of the desired sequence > 3. Inspect to value of the global variable (exactally as it's done in > MsSQL) Not sure if this thread is about global variables or just how to use sequences, but ... if you want variables that are global, you can use a table (global to all processes), a temp table (global to everything inside one connection), or a row in a global table (can be either). I tend to keep one global table of (key,value) pairs, with a primary key constraint so that the query optimizer knows that "SELECT val FROM Env WHERE key='xxx'" will return at most 1 row. The "keys" are actually structured paths ("mail.process.thread_limit").