Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Register COALESCE function. Update docs. Add integration test to engine. #437

Merged
merged 1 commit into from
Oct 10, 2018
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ We support and actively test against certain third-party clients to ensure compa
- `ARRAY_LENGTH(json)`: If the json representation is an array, this function returns its size.
- `SPLIT(str,sep)`: Receives a string and a separator and returns the parts of the string split by the separator as a JSON array of strings.
- `CONCAT(...)`: Concatenate any group of fields into a single string.
- `COALESCE(...)`: The function returns the first non-null value in a list.

## Example

Expand Down Expand Up @@ -122,7 +123,7 @@ func createTestDatabase() *mem.Database {
for _, row := range rows {
table.Insert(ctx, row)
}

return db
}

Expand Down
1 change: 1 addition & 0 deletions SUPPORTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
- IS_BINARY
- SPLIT
- SUBSTRING
- COALESCE

## Time functions
- DAY
Expand Down
12 changes: 12 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ var queries = []struct {
{string("abc")},
},
},
{
`SELECT COALESCE(NULL, NULL, NULL, 'example', NULL, 1234567890)`,
[]sql.Row{
{string("example")},
},
},
{
`SELECT COALESCE(NULL, NULL, NULL, COALESCE(NULL, 1234567890))`,
[]sql.Row{
{int64(1234567890)},
},
},
{
"SELECT concat(s, i) FROM mytable",
[]sql.Row{
Expand Down
5 changes: 3 additions & 2 deletions sql/expression/function/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ var Defaults = sql.Functions{
"array_length": sql.Function1(NewArrayLength),
"split": sql.Function2(NewSplit),
"concat": sql.FunctionN(NewConcat),
"lower": sql.Function1(NewLower),
"upper": sql.Function1(NewUpper),
"lower": sql.Function1(NewLower),
"upper": sql.Function1(NewUpper),
"ceiling": sql.Function1(NewCeil),
"ceil": sql.Function1(NewCeil),
"floor": sql.Function1(NewFloor),
"round": sql.FunctionN(NewRound),
"coalesce": sql.FunctionN(NewCoalesce),
}