-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
implement elt()
and field()
function
#2262
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm mostly, testing for this one is a bit tricker
return nil, sql.ErrInvalidArgumentNumber.New("ELT", "2 or more", len(args)) | ||
} | ||
|
||
return &Elt{args}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we validate the arg types? what happens if one of these isn't a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like non-string types are OK actually, these two both return 2
select field(2, 'a',2);
select field(2, 'a','2');
sql/expression/function/field.go
Outdated
|
||
// Type implements the Expression interface. | ||
func (f *Field) Type() sql.Type { | ||
return types.Int32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mysql reports this as a long when I'm testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I get when running on MySQL with --column-type-info
mysql> select field('a', 'a');
Field 1
Name: `field('a', 'a')`
Org_name: ``
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: Integer
DbType: TINY
Collation: binary (63)
Length: 3
Decimals: 0
Flags: NOT_NULL NUM
+-----------------+
| field('a', 'a') |
+-----------------+
| 1 |
+-----------------+
1 row in set (0.0003 sec)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what i get, mysql 8.0.2
mysql> select field('a', 'a');
Field 1: `field('a', 'a')`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: LONGLONG
Collation: binary (63)
Length: 3
Max_length: 1
Decimals: 0
Flags: NOT_NULL BINARY NUM
+-----------------+
| field('a', 'a') |
+-----------------+
| 1 |
+-----------------+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
This PR implements the
ELT()
function, which just returns the nth argument as a string.This PR also implements the
FIELD()
function, which returns the first case-insensitive match to the first argument.MySQL Docs: