Changeset: 813e6458abdf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/813e6458abdf
Modified Files:
        sql/server/rel_updates.c
        sql/server/sql_parser.y
Branch: default
Log Message:

Add DECIMAL DELIMITER clause to COPY INTO syntax

Because of how the parser works,
DEC DELIMITER and NUMERIC DELIMITER are also accepted.
I kind of like that.


diffs (124 lines):

diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -1555,7 +1555,7 @@ rel_import(mvc *sql, sql_table *t, const
 }
 
 static sql_rel *
-copyfrom(sql_query *query, dlist *qname, dlist *columns, dlist *files, dlist 
*headers, dlist *seps, dlist *nr_offset, str null_string, int best_effort, 
dlist *fwf_widths, int onclient, int escape)
+copyfrom(sql_query *query, dlist *qname, dlist *columns, dlist *files, dlist 
*headers, dlist *seps, dlist *nr_offset, str null_string, int best_effort, 
dlist *fwf_widths, int onclient, int escape, dlist *decimal_seps)
 {
        mvc *sql = query->sql;
        sql_rel *rel = NULL;
@@ -1570,6 +1570,8 @@ copyfrom(sql_query *query, dlist *qname,
        lng offset = (nr_offset)?nr_offset->h->next->data.l_val:0;
        list *collist;
        int reorder = 0;
+       const char *decsep = decimal_seps->h->data.sval;
+
        assert(!nr_offset || nr_offset->h->type == type_lng);
        assert(!nr_offset || nr_offset->h->next->type == type_lng);
 
@@ -1583,6 +1585,14 @@ copyfrom(sql_query *query, dlist *qname,
                                "that will never match, use '\\n' instead");
        }
 
+       if (strlen(decsep) != 1
+                       || decsep[0] <= ' '
+                       || decsep[0] >= 127
+                       || decsep[0] == '-' || decsep[0] == '+'
+                       || (decsep[0] >= '0' && decsep[0] <= '9')) {
+               return sql_error(sql, 02, SQLSTATE(42000) "COPY INTO: invalid 
decimal separator");
+       }
+
        t = find_table_or_view_on_scope(sql, NULL, sname, tname, "COPY INTO", 
false);
        if (insert_allowed(sql, t, tname, "COPY INTO", "copy into") == NULL)
                return NULL;
@@ -2089,7 +2099,8 @@ rel_updates(sql_query *query, symbol *s)
                                
l->h->next->next->next->next->next->next->next->data.i_val,
                                
l->h->next->next->next->next->next->next->next->next->data.lval,
                                
l->h->next->next->next->next->next->next->next->next->next->data.i_val,
-                               
l->h->next->next->next->next->next->next->next->next->next->next->data.i_val);
+                               
l->h->next->next->next->next->next->next->next->next->next->next->data.i_val,
+                               
l->h->next->next->next->next->next->next->next->next->next->next->next->data.lval);
                sql->type = Q_UPDATE;
        }
                break;
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
@@ -490,6 +490,7 @@ int yydebug=1;
        opt_referencing_list
        opt_schema_element_list
        opt_seps
+       opt_decimal_seps
        opt_seq_params
        opt_typelist
        opt_with_encrypted_password
@@ -2918,8 +2919,8 @@ opt_on_location:
   ;
 
 copyfrom_stmt:
-//  1    2      3    4     5               6    7                8             
  9               10       11         12              13              14
-    COPY opt_nr INTO qname opt_column_list FROM string_commalist 
opt_header_list opt_on_location opt_seps opt_escape opt_null_string 
opt_best_effort opt_fwf_widths
+//  1    2      3    4     5               6    7                8             
  9               10       11               12         13              14       
       15
+    COPY opt_nr INTO qname opt_column_list FROM string_commalist 
opt_header_list opt_on_location opt_seps opt_decimal_seps opt_escape 
opt_null_string opt_best_effort opt_fwf_widths
        { dlist *l = L();
          append_list(l, $4);
          append_list(l, $5);
@@ -2927,14 +2928,15 @@ copyfrom_stmt:
          append_list(l, $8);
          append_list(l, $10);
          append_list(l, $2);
-         append_string(l, $12);
-         append_int(l, $13);
-         append_list(l, $14);
+         append_string(l, $13);
+         append_int(l, $14);
+         append_list(l, $15);
          append_int(l, $9);
-         append_int(l, $11);
+         append_int(l, $12);
+         append_list(l, $11);
          $$ = _symbol_create_list( SQL_COPYFROM, l ); }
-//  1    2      3    4     5               6    7      8               9       
 10         11              12
-  | COPY opt_nr INTO qname opt_column_list FROM STDIN  opt_header_list 
opt_seps opt_escape opt_null_string opt_best_effort
+//  1    2      3    4     5               6    7      8               9       
 10               11         12              13
+  | COPY opt_nr INTO qname opt_column_list FROM STDIN  opt_header_list 
opt_seps opt_decimal_seps opt_escape opt_null_string opt_best_effort
        { dlist *l = L();
          append_list(l, $4);
          append_list(l, $5);
@@ -2942,11 +2944,12 @@ copyfrom_stmt:
          append_list(l, $8);
          append_list(l, $9);
          append_list(l, $2);
-         append_string(l, $11);
-         append_int(l, $12);
+         append_string(l, $12);
+         append_int(l, $13);
          append_list(l, NULL);
          append_int(l, 0);
-         append_int(l, $10);
+         append_int(l, $11);
+         append_list(l, $10);
          $$ = _symbol_create_list( SQL_COPYFROM, l ); }
 //  1    2         3    4     5    6
   | COPY sqlLOADER INTO qname FROM func_ref
@@ -3051,6 +3054,17 @@ opt_seps:
                                  $$ = l; }
  ;
 
+opt_decimal_seps:
+       /* empty */
+                               { dlist *l = L();
+                                 append_string(l, sa_strdup(SA, "."));
+                                 $$ = l; }
+       | sqlDECIMAL DELIMITERS string
+                               { dlist *l = L();
+                                 append_string(l, $3);
+                                 $$ = l; }
+;
+
 opt_using:
     /* empty */                        { $$ = NULL; }
  |  USING                      { $$ = NULL; }
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to