Thursday , April 25 2024

PostgreSQL Generated Column

PostgreSQL Generated Column (Computed Column) is an operation on two or more columns and printing them into a different column.

Computed Column is available with postgresql12.

STORED parameter: It is used to read the value written in the column when it is wanted to be written and read while inserting the table.

VIRTUAL parameter: It is not written while inserting into the table, and when it is wanted to be read, it is calculated by using the view logic and the result is returned.

Let’s reinforce it with an example.

First, let’s create our 3-column table. The first two columns are the column we will use to enter our data, and the last column is the column where the sum of the two columns will be printed.

We created the table. Let’s insert our data as follows.

We have inserted the data. Let’s see the result by selecting from the table.

As seen above, when we enter the values in the number1 and number2 column, the total value of the number1 and number2 column is printed in the totalvalue column.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories