Re: Using Transaction with if-else in prepared statement - Mailing list pgsql-sql

From hubert depesz lubaczewski
Subject Re: Using Transaction with if-else in prepared statement
Date
Msg-id 20220525233556.GA9042@depesz.com
Whole thread Raw
In response to Using Transaction with if-else in prepared statement  (Hui Jackson <jackhts4@gmail.com>)
Responses Re: Using Transaction with if-else in prepared statement
List pgsql-sql
On Wed, May 25, 2022 at 07:12:49PM +0800, Hui Jackson wrote:
> I am trying to make transaction in nodejs
> The logic will be check if sufficient coin in sender's amount, if
> sufficient then do transaction.
> I am new to postgres, not sure if this is a right way to do so, if you have
> a better solution, please let me know, thank you.

I would do i by issuing *only*
INSERT INTO coin_history(sender_id, receiver_id, amount) VALUES
and then changing coin data with triggers plus adding constraints that
app_user.coin can never be < 0.

depesz



pgsql-sql by date:

Previous
From: Steve Midgley
Date:
Subject: Re: Using Transaction with if-else in prepared statement
Next
From: Hui Jackson
Date:
Subject: Re: Using Transaction with if-else in prepared statement