Skip to content

Commit

Permalink
Merge pull request #11675 from knz/extend-typeof
Browse files Browse the repository at this point in the history
sql: make pg_typeof work with all types.
  • Loading branch information
knz authored Nov 29, 2016
2 parents 7fee49f + f511c5d commit 7b73805
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
16 changes: 1 addition & 15 deletions pkg/sql/parser/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,21 +1394,7 @@ var Builtins = map[string][]Builtin{
// TODO(knz): This is a proof-of-concept until TypeAny works
// properly.
Builtin{
Types: ArgTypes{TypeInt},
ReturnType: TypeString,
fn: func(_ *EvalContext, args DTuple) (Datum, error) {
return NewDString(args[0].ResolvedType().String()), nil
},
},
Builtin{
Types: ArgTypes{TypeDecimal},
ReturnType: TypeString,
fn: func(_ *EvalContext, args DTuple) (Datum, error) {
return NewDString(args[0].ResolvedType().String()), nil
},
},
Builtin{
Types: ArgTypes{TypeString},
Types: ArgTypes{TypeAny},
ReturnType: TypeString,
fn: func(_ *EvalContext, args DTuple) (Datum, error) {
return NewDString(args[0].ResolvedType().String()), nil
Expand Down
21 changes: 21 additions & 0 deletions pkg/sql/testdata/builtin_function
Original file line number Diff line number Diff line change
Expand Up @@ -1333,3 +1333,24 @@ query T
SELECT pg_catalog.pg_typeof(sign(1:::decimal))
----
decimal

query T
VALUES (pg_typeof(1:::int)),
(pg_typeof('a':::string)),
(pg_typeof(true)),
(pg_typeof(null)),
(pg_typeof('3m':::interval)),
(pg_typeof('2016-11-12':::date)),
(pg_typeof(now():::timestamptz)),
(pg_typeof(b'a':::bytes)),
(pg_typeof(array[1,2,3]))
----
int
string
bool
NULL
interval
date
timestamptz
bytes
int[]

0 comments on commit 7b73805

Please sign in to comment.