Changeset: 1007e9b740c4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1007e9b740c4
Modified Files:
sql/common/sql_types.c
sql/scripts/49_strings.sql
sql/server/sql_parser.y
sql/server/sql_scan.c
Branch: literal_features
Log Message:
move TRIM including new OVER syntax to parser and sql_types function rename of
'trim' to 'btrim'
diffs (112 lines):
diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -1513,8 +1513,8 @@ sqltypeinit( sql_allocator *sa)
sql_create_func(sa, "ucase", "str", "toUpper", FALSE, FALSE,
INOUT, 0, *t, 1, *t);
sql_create_func(sa, "lower", "str", "toLower", FALSE, FALSE,
INOUT, 0, *t, 1, *t);
sql_create_func(sa, "lcase", "str", "toLower", FALSE, FALSE,
INOUT, 0, *t, 1, *t);
- sql_create_func(sa, "trim", "str", "trim", FALSE, FALSE, INOUT,
0, *t, 1, *t);
- sql_create_func(sa, "trim", "str", "trim2", FALSE, FALSE,
INOUT, 0, *t, 2, *t, *t);
+ sql_create_func(sa, "btrim", "str", "trim", FALSE, FALSE,
INOUT, 0, *t, 1, *t);
+ sql_create_func(sa, "btrim", "str", "trim2", FALSE, FALSE,
INOUT, 0, *t, 2, *t, *t);
sql_create_func(sa, "ltrim", "str", "ltrim", FALSE, FALSE,
INOUT, 0, *t, 1, *t);
sql_create_func(sa, "ltrim", "str", "ltrim2", FALSE, FALSE,
INOUT, 0, *t, 2, *t, *t);
sql_create_func(sa, "rtrim", "str", "rtrim", FALSE, FALSE,
INOUT, 0, *t, 1, *t);
diff --git a/sql/scripts/49_strings.sql b/sql/scripts/49_strings.sql
--- a/sql/scripts/49_strings.sql
+++ b/sql/scripts/49_strings.sql
@@ -57,11 +57,3 @@ grant execute on filter function contain
create filter function sys.contains(x string, y string, icase boolean)
external name str.contains;
grant execute on filter function contains(string, string, boolean) to public;
-
-create function sys.btrim(x string)
-returns string external name str.trim;
-grant execute on function btrim(string) to public;
-
-create function sys.btrim(x string, y string)
-returns string external name str.trim2;
-grant execute on function btrim(string, string) to public;
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -698,7 +698,7 @@ int yydebug=1;
%left <operation> ALL ANY NOT_BETWEEN BETWEEN NOT_IN sqlIN NOT_EXISTS EXISTS
NOT_LIKE LIKE NOT_ILIKE ILIKE OR SOME
%left <operation> AND
%left <sval> COMPARISON /* <> < > <= >= */
-%left <operation> '+' '-' '&' '|' '^' LEFT_SHIFT RIGHT_SHIFT LEFT_SHIFT_ASSIGN
RIGHT_SHIFT_ASSIGN CONCATSTRING SUBSTRING TROM POSITION SPLIT_PART
+%left <operation> '+' '-' '&' '|' '^' LEFT_SHIFT RIGHT_SHIFT LEFT_SHIFT_ASSIGN
RIGHT_SHIFT_ASSIGN CONCATSTRING SUBSTRING TRIM POSITION SPLIT_PART
%left <operation> '*' '/' '%'
%left UMINUS
%left <operation> '~'
@@ -4507,14 +4507,14 @@ opt_brackets:
;
opt_trim_type:
- /* empty */ { $$ = "btrim"; }
+ /* empty */ { $$ = NULL; }
| LEADING {$$ = "ltrim"; }
| TRAILING {$$ = "rtrim"; }
| BOTH {$$ = "btrim"; }
;
opt_trim_characters:
- /* empty */ { $$ = " "; }
+ /* empty */ { $$ = NULL; }
| string {$$ = $1; }
;
@@ -4584,19 +4584,38 @@ string_funcs:
append_symbol(ops, $7);
append_list(l, ops);
$$ = _symbol_create_list( SQL_NOP, l ); }
-| TROM '(' opt_trim_type opt_trim_characters FROM scalar_exp ')'
+| TRIM '(' opt_trim_type opt_trim_characters FROM scalar_exp ')'
{ dlist *l = L();
+ if ( $3 == NULL && $4 == NULL ) {
+ sqlformaterror(m, SQLSTATE(2000) "%s", "trim
specification or trim characters need to be specified preceding FROM in TRIM");
+ YYABORT;
+ }
append_list(l,
- append_string(L(), sa_strdup(SA, $3)));
+ append_string(L(), sa_strdup(SA,
$3?$3:"btrim")));
append_int(l, FALSE); /* ignore distinct */
append_symbol(l, $6);
- char* s = $4;
+ char* s = $4?$4:" ";
int len = UTF8_strlen(s);
sql_subtype t;
sql_find_subtype(&t, "char", len, 0 );
append_symbol(l, _newAtomNode( _atom_string(&t, s)));
$$ = _symbol_create_list( SQL_BINOP, l ); }
+| TRIM '(' scalar_exp ',' scalar_exp ')'
+ { dlist *l = L();
+ append_list(l,
+ append_string(L(), sa_strdup(SA, "btrim")));
+ append_int(l, FALSE); /* ignore distinct */
+ append_symbol(l, $3);
+ append_symbol(l, $5);
+ $$ = _symbol_create_list( SQL_BINOP, l ); }
+| TRIM '(' scalar_exp ')'
+ { dlist *l = L();
+ append_list(l,
+ append_string(L(), sa_strdup(SA, "btrim")));
+ append_int(l, FALSE); /* ignore distinct */
+ append_symbol(l, $3);
+ $$ = _symbol_create_list( SQL_UNOP, l ); }
;
column_exp_commalist:
diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c
--- a/sql/server/sql_scan.c
+++ b/sql/server/sql_scan.c
@@ -351,7 +351,7 @@ scanner_init_keywords(void)
failed += keywords_insert("POSITION", POSITION);
failed += keywords_insert("SUBSTRING", SUBSTRING);
failed += keywords_insert("SPLIT_PART", SPLIT_PART);
- failed += keywords_insert("TROM", TROM);
+ failed += keywords_insert("TRIM", TRIM);
failed += keywords_insert("LEADING", LEADING);
failed += keywords_insert("TRAILING", TRAILING);
failed += keywords_insert("BOTH", BOTH);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]