Re: Using Transaction with if-else in prepared statement

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Hui Jackson <jackhts4(at)gmail(dot)com>
Cc: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: Using Transaction with if-else in prepared statement
Date: 2022-05-25 23:35:56
Message-ID: 20220525233556.GA9042@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Hui Jackson 2022-05-26 10:00:49 Re: Using Transaction with if-else in prepared statement
Previous Message Steve Midgley 2022-05-25 18:03:34 Re: Using Transaction with if-else in prepared statement