variables in pgSQL?

From: Heinz Hemken <zotz(at)franchiseloan(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: variables in pgSQL?
Date: 1999-07-13 02:41:54
Message-ID: 378AA772.84903F66@franchiseloan.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Chris Bitmead 1999-07-13 03:12:49 Re: [SQL] variables in pgSQL?
Previous Message Steven Bradley 1999-07-13 02:31:05 create temp table