Skip site navigation (1) Skip section navigation (2)

Re: [NOVICE] PostgreSQL problem with functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Nikola Milutinovic" <Nikola(dot)Milutinovic(at)ev(dot)co(dot)yu>
Cc: "PostgreSQL general" <pgsql-general(at)postgresql(dot)org>, "PostgreSQL novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: [NOVICE] PostgreSQL problem with functions
Date: 2001-06-12 13:47:00
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-novice
LOCK TABLE IN EXCLUSIVE MODE is hardly the way to program a function
that you want to be able to invoke concurrently from multiple backends.
Moreover, "SELECT max()" is going to be slow --- and you're doing it
while holding the exclusive lock!  Concurrent performance is gonna be

A much better solution to your problem is to use a sequence object to
generate the ID values.  For example:

	new_id := nextval(''seq_name'');
	INSERT INTO admin_session VALUES (new_id, a_ss, ''now'', ...);
	return new_id;

BTW, this could be the complete body of your function.  The "SELECT FROM
a_user" check would be better handled by defining a foreign-key
constraint on the a_id column.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: James McMurryDate: 2001-06-12 19:00:27
Subject: Re: selecting a column average into table
Previous:From: Giorgio A.Date: 2001-06-12 10:52:11
Subject: Re: Urgent

pgsql-general by date

Next:From: Mitch VincentDate: 2001-06-12 14:22:12
Subject: Re: How many no. of clients can access database simultaneously?
Previous:From: Jeff EckermannDate: 2001-06-12 13:37:33
Subject: RE: Large OR query

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group