Re: Check before INSERT INTO

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Shavonne Marietta Wijesinghe" <shavonne(dot)marietta(at)studioform(dot)it>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Check before INSERT INTO
Date: 2008-02-11 16:56:03
Message-ID: 87ve4vqvoc.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Shavonne Marietta Wijesinghe" <shavonne(dot)marietta(at)studioform(dot)it> writes:

> Thanks for the reply Grogory. I am trying to do a INSERT INTO.
>
> Here is my table. n_gen, n_sheet, tot_n_sheet are defined as Primary Key
> (Serial not null)
> id | n_gen | n_sheet | tot_n_sheet
> ----------+-----------+-----------+-------------
> a | 1 | 1 | 1
> b | 2 | 1 | 2
> x | 2 | 2 | 2
> u | 3 | 1 | 1
> r | 4 | 1 | 3
> a | 4 | 2 | 3
> s | 4 | 3 | 3
>
>
> So there are 2 users inserting in to the db. In my ASP page i have a field that
> shows the value of n_gen +1. So when the 2 users both login at the same time,
> with different sessions, they both see "7" in the n_gen field. But when they
> click on the sumbit button only one record is inserted and the other is lost.
>
> I though it was possible to change the SQL string before it does the update..
> But i can't seem to find a solution for it.. Any idea ??

You'll have to explain what you want n_gen to contain.

Then you'll have to decide whether you want to do this in ASP where you can
certainly change the SQL all you like, or on the server where you can have
triggers which change the values being stored or executing additional queries.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's PostGIS support!

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2008-02-11 16:56:33 Re: Usage of UUID with 8.3 (Windows)
Previous Message Jean-David Beyer 2008-02-11 16:55:22 Re: Check before INSERT INTO