Received: from spogg.ifc-mailer.com ([38.187.40.163]) by hub.org (8.9.3/8.9.3) with ESMTP id WAA90185 for ; Mon, 12 Jul 1999 22:18:58 -0400 (EDT) (envelope-from zotz@franchiseloan.com) Received: (from bin@localhost) by spogg.ifc-mailer.com (8.8.7/8.8.7) id SAA16210 for ; Mon, 12 Jul 1999 18:22:14 -0700 X-Authentication-Warning: spogg.ifc-mailer.com: bin set sender to using -f Received: from ocean(172.20.20.14) by spogg via smap (V2.1) id xma016208; Mon, 12 Jul 99 18:22:03 -0700 Message-ID: <378AA1FC.41FBE96C@franchiseloan.com> Date: Mon, 12 Jul 1999 19:18:36 -0700 From: Heinz Hemken Organization: IFC Capital X-Mailer: Mozilla 4.6 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: variables in pgSQL? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit The following is legal in MS SQL: declare @user_id int select @user_id = user_id from masterindex_table where masterindexid = 1 whereupon the local variable can be used for other things. Is there anything similar in pgSQL? I want to have a user table for a web database, and I want to be able to do a begin/commit block where I 1) check to see if the user exists in an account table, 2) if not, get the next available userid from a master index table, 3) add a new userid to the account table for the new user, and 4) increment the userid field in the master index table. I want this to occur all within a single transaction block so that no race conditions exist, and the masterindex table is only being used by one process at a time for the whole operation. How can I do this in postgresql? Is there a better approach? -- Heinz Hemken IFC Capital Corporation San Diego, California