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

sql: allow NULL in create view definition #85134

Merged
merged 1 commit into from
Aug 1, 2022
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
6 changes: 5 additions & 1 deletion pkg/sql/create_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,11 @@ func addResultColumns(
resultColumns colinfo.ResultColumns,
) error {
for _, colRes := range resultColumns {
columnTableDef := tree.ColumnTableDef{Name: tree.Name(colRes.Name), Type: colRes.Typ}
colTyp := colRes.Typ
if colTyp.Family() == types.UnknownFamily {
colTyp = types.String
}
columnTableDef := tree.ColumnTableDef{Name: tree.Name(colRes.Name), Type: colTyp}
// Nullability constraints do not need to exist on the view, since they are
// already enforced on the source data.
columnTableDef.Nullable.Nullability = tree.SilentNull
Expand Down
21 changes: 21 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/views
Original file line number Diff line number Diff line change
Expand Up @@ -1313,3 +1313,24 @@ DROP MATERIALIZED VIEW mv1

statement ok
DROP MATERIALIZED VIEW mv2

statement ok
CREATE VIEW view_with_null AS SELECT 1 AS a, null AS c

query TTBTTTB
SHOW COLUMNS FROM view_with_null
----
a INT8 true NULL · {} false
c STRING true NULL · {} false


statement ok
CREATE MATERIALIZED VIEW materialized_view_with_null AS SELECT a, NULL AS b, b AS c FROM test_view

query TTBTTTB
SHOW COLUMNS FROM materialized_view_with_null
----
a INT8 true NULL · {materialized_view_with_null_pkey} false
b STRING true NULL · {materialized_view_with_null_pkey} false
c INT8 true NULL · {materialized_view_with_null_pkey} false
rowid INT8 false unique_rowid() · {materialized_view_with_null_pkey} true