February 2, 2023

SharewarePile.com – Latest Web Hosting News

Latest Web Development and Hosting News

Problem with data type

Hi. I have a column in postgres that is generated by two columns. This is a definition

total_amount numeric(13,2) NOT NULL GENERATED ALWAYS AS ((debit_amount – credit_amount)) STORED

So total_amount column is always generated out of (debit_amount – credit_amount). I have a request to hold the same definition only if total_amount column is not appearing in the insert statement. When total_amount is appearing it should not look out to the above definition
example of insert object 1

{
debit_amount: 1000,

credit_amount: 0

}

total_amount use definition because it is not appearing in the insert statement (1000 – 0) = 1000

example of insert object 2

{

debit_amount: 0,

credit_amount: 0,

total_amount: 10000

}

total_amount shuoldn’t use definition and should be = 10000

Is there any data type in postgresql to support this kind of request?
If not, do you have any idea how to create a custom type for this?

Thank you for your answer!

submitted by /u/marcos351
[link] [comments]


Go to Source of this post
Author Of this post: /u/marcos351
Title Of post: Problem with data type
Author Link: {authorlink}