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 84F003A3EEC for ; Wed, 17 Nov 2004 13:49:11 +0000 (GMT) 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 70051-03 for ; Wed, 17 Nov 2004 13:49:02 +0000 (GMT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by svr1.postgresql.org (Postfix) with ESMTP id AE7373A3ECC for ; Wed, 17 Nov 2004 13:49:02 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 4.42) id 1CUQBO-0004CS-3i; Wed, 17 Nov 2004 13:49:14 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 0CB41172CC; Wed, 17 Nov 2004 13:49:01 +0000 (GMT) Message-ID: <419B56CC.8090703@archonet.com> Date: Wed, 17 Nov 2004 13:49:00 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.9 (X11/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 To: abief_ag_-postgresql@yahoo.com Cc: pgsql-sql@postgresql.org Subject: Re: session_id References: <20041117131344.90253.qmail@web13922.mail.yahoo.com> In-Reply-To: <20041117131344.90253.qmail@web13922.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/169 X-Sequence-Number: 19488 Riccardo G. Facchini wrote: > hi all, > > is there a way to determine the session id on a database session? > > I would need to have a unique number whenever a session is started, and > have this available as a function or view result. Add a new sequence to your database: CREATE SEQUENCE my_session_id; Then, at the start of every session: SELECT nextval('my_session_id'); and whenever you need the value: SELECT currval('my_session_id'); Sequences are concurrency-safe, so you're OK with multiple clients. They return INT8 values, so you should be good for unique numbers for a while. The only thing is, you need to remember to call nextval() every time you connect. HTH -- Richard Huxton Archonet Ltd