Skip to content

Commit

Permalink
Merge #72294
Browse files Browse the repository at this point in the history
72294: tree: allow string->tuple cast r=otan a=rafiss

This is a follow-up / forgotten case from
b376038

No release note, since the note on the other commit covers it.

Release note: None

Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
craig[bot] and rafiss committed Nov 3, 2021
2 parents 3687a44 + ab420f0 commit 1df6519
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 1df6519

Please sign in to comment.