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

tree: allow string->tuple cast #72294

Merged
merged 1 commit into from
Nov 3, 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
12 changes: 11 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/record
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ CREATE VIEW v AS SELECT (1,'a')::b
statement error cannot modify table record type
CREATE VIEW v AS SELECT ((1,'a')::b).a

# Test parsing of record types from string literals.
# Test parsing/casting of record types from string literals.

query T
SELECT COALESCE(ARRAY[ROW(1, 2)], '{}')
Expand All @@ -170,3 +170,13 @@ query T
SELECT COALESCE(NULL::a[], '{"(1, 3)", "(1, 2)"}');
----
{"(1,\" 3\")","(1,\" 2\")"}

statement ok
CREATE TABLE strings(s TEXT);
INSERT INTO strings VALUES('(1,2)'), ('(5,6)')

query TT
SELECT s, s::a FROM strings ORDER BY 1
----
(1,2) (1,2)
(5,6) (5,6)
4 changes: 4 additions & 0 deletions pkg/sql/sem/tree/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ var validCasts = []castInfo{
// Casts to TupleFamily.
{from: types.UnknownFamily, to: types.TupleFamily, volatility: VolatilityImmutable},
{from: types.TupleFamily, to: types.TupleFamily, volatility: VolatilityStable},
{from: types.StringFamily, to: types.TupleFamily, volatility: VolatilityStable},
}

type castsMapKey struct {
Expand Down Expand Up @@ -2366,6 +2367,9 @@ func performCastWithoutPrecisionTruncation(
}
}
return ret, nil
case *DString:
res, _, err := ParseDTupleFromString(ctx, string(*v), t)
return res, err
}
}

Expand Down