/
type_name.go
38 lines (34 loc) · 976 Bytes
/
type_name.go
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
// Copyright 2023 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package cast
import (
"strings"
"github.com/cockroachdb/cockroachdb-parser/pkg/sql/types"
"github.com/lib/pq/oid"
)
// CastTypeName returns the name of the type used for casting.
func CastTypeName(t *types.T) string {
// SQLString is wrong for these types.
switch t.Oid() {
case oid.T_numeric:
// SQLString returns `decimal`
return "numeric"
case oid.T_char:
// SQLString returns `"char"`
return "char"
case oid.T_bpchar:
// SQLString returns `char`.
return "bpchar"
case oid.T_text:
// SQLString returns `string`
return "text"
}
return strings.ToLower(t.SQLString())
}