Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-21.1: sql: copy VIRTUAL columns in CREATE TABLE LIKE #63172

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,7 @@ func replaceLikeTableOpts(n *tree.CreateTable, params runParams) (tree.TableDefs
if c.ComputeExpr != nil {
if opts.Has(tree.LikeTableOptGenerated) {
def.Computed.Computed = true
def.Computed.Virtual = c.Virtual
def.Computed.Expr, err = parser.ParseExpr(*c.ComputeExpr)
if err != nil {
return nil, err
Expand Down
17 changes: 17 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/virtual_columns
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,20 @@ COMMIT;

statement ok
DROP TABLE t_ref;

# Regression test for #63167. CREATE TABLE LIKE should copy VIRTUAL columns as
# VIRTUAL, not STORED.
statement ok
CREATE TABLE t63167_a (a INT, v INT AS (a + 1) VIRTUAL);
CREATE TABLE t63167_b (LIKE t63167_a INCLUDING ALL);

query T
SELECT create_statement FROM [SHOW CREATE TABLE t63167_b]
----
CREATE TABLE public.t63167_b (
a INT8 NULL,
v INT8 NULL AS (a + 1:::INT8) VIRTUAL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (a, rowid)
)