Postgresql generated columns

Moki Lv6

Stored

1
2
3
4
5
6
7
8
9
10
11
12
13
14
create table example
(
id bigint generated always as identity,
a integer ,
b integer ,
c integer GENERATED ALWAYS AS
(CASE
WHEN ((a IS NOT NULL) AND
(b IS NOT NULL) AND
(b > 0))
THEN floor(((a / b))::double precision)
ELSE NULL::double precision
END) STORED
)
1
2
3
4
5
6
create table example
(
id bigint generated always as identity,
a timestamp not null ,
b char(4) GENERATED ALWAYS AS (EXTRACT(year FROM date))::text) STORED
)

Virtual column

1
2
3
4
5
6
7
8
9
10
11
12
13
14
create table example
(
id bigint generated always as identity,
a integer ,
b integer ,
c integer GENERATED ALWAYS AS
(CASE
WHEN ((a IS NOT NULL) AND
(b IS NOT NULL) AND
(b > 0))
THEN floor(((a / b))::double precision)
ELSE NULL::double precision
END)
)
1
2
3
4
5
6
create table example
(
id bigint generated always as identity,
a timestamp not null ,
b char(4) GENERATED ALWAYS AS (EXTRACT(year FROM date))::text)
)
On this page
Postgresql generated columns