1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
# Skip PostgreSQL 10, 11 as they do not support generated columns.
! only postgres10|postgres11
apply 1.hcl
cmpshow users 1.sql
! apply 2.fail1.hcl 'changing column "a" to generated column is not supported (drop and add is required)'
! apply 2.fail2.hcl 'changing the generation expression for a column "b" is not supported'
# Skip PostgreSQL 12 as it does not support 'DROP EXPRESSION'.
! only postgres12
apply 3.hcl
cmpshow users 3.sql
-- 1.hcl --
schema "$db" {}
table "users" {
schema = schema.$db
column "a" {
type = int
}
column "b" {
type = int
as = "1"
}
column "c" {
type = int
as {
expr = "2"
type = STORED
}
}
}
-- 1.sql --
Table "script_column_generated.users"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+--------------------------------
a | integer | | not null |
b | integer | | not null | generated always as (1) stored
c | integer | | not null | generated always as (2) stored
-- 2.fail1.hcl --
schema "$db" {}
table "users" {
schema = schema.$db
column "a" {
type = int
as = "0"
}
column "b" {
type = int
as = "1"
}
column "c" {
type = int
as {
expr = "2"
type = STORED
}
}
}
-- 2.fail2.hcl --
schema "$db" {}
table "users" {
schema = schema.$db
column "a" {
type = int
}
column "b" {
type = int
as = "2"
}
column "c" {
type = int
as {
expr = "3"
type = STORED
}
}
}
-- 3.hcl --
schema "$db" {}
table "users" {
schema = schema.$db
column "a" {
type = int
}
column "b" {
type = int
}
column "c" {
type = int
}
}
-- 3.sql --
Table "script_column_generated.users"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
a | integer | | not null |
b | integer | | not null |
c | integer | | not null |
|