Changeset: deed230d20d4 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=deed230d20d4
Modified Files:
sql/backends/monet5/sql.mx
sql/server/sql_parser.y
sql/test/snodgrass/Tests/cast_select.stable.out
sql/test/snodgrass/cast_select.sql
Branch: Dec2011
Log Message:
small fixes on time/timestamp and date (todo interval precision)
diffs (151 lines):
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -1355,7 +1355,6 @@ sql5_export str second_interval_@1( lng
@:c_interval_export(wrd)@
@:c_interval_export(lng)@
@:c_interval_export(daytime)@
-sql5_export str second_interval_2_daytime( daytime *res, lng *s, int *d);
@= simpleupcast_export
sql5_export str @2_2_@1( @1 *res, @2 *v );
sql5_export str bat@2_2_@1( int *res, int *v );
@@ -4214,6 +4213,30 @@ str_2time_daytime( daytime *res, str *v,
}
str
+timestamp_2_daytime( daytime *res, timestamp *v, int *digits )
+{
+ int d = (*digits)?*digits-1:0;
+ int msec = v->msecs;
+
+ /* correct fraction */
+ if (d < 3 && msec) {
+ msec /= scales[3-d];
+ msec *= scales[3-d];
+ }
+ *res = msec;
+ return MAL_SUCCEED;
+}
+
+str
+date_2_timestamp( timestamp *res, date *v, int *digits )
+{
+ (void)digits; /* no precision needed */
+ res->days = *v;
+ res->msecs = 0;
+ return MAL_SUCCEED;
+}
+
+str
timestamp_2time_timestamp( timestamp *res, timestamp *v, int *digits )
{
int d = (*digits)?*digits-1:0;
@@ -5563,8 +5586,19 @@ comment "cast daytime to a second_interv
command calc.daytime( v:lng, d:int) :daytime
address second_interval_2_daytime
comment "cast second_interval to a daytime and check for overflow";
+
+command calc.daytime( v:timestamp, d:int) :daytime
+address timestamp_2_daytime
+comment "cast timestamp to a daytime and check for overflow";
+
+command calc.timestamp( v:date, d:int) :timestamp
+address date_2_timestamp
+comment "cast date to a timestamp and check for overflow";
@h
sql5_export str second_interval_daytime( lng *res, daytime *s, int *ek, int
*sk );
+sql5_export str second_interval_2_daytime( daytime *res, lng *s, int *d);
+sql5_export str timestamp_2_daytime( daytime *res, timestamp *v, int *d);
+sql5_export str date_2_timestamp( timestamp *res, date *v, int *d);
@c
str
second_interval_daytime( lng *res, daytime *s, int *d, int *sk )
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
@@ -4182,6 +4182,7 @@ interval_expression:
YYABORT;
} else {
/* count the number of digits in the input */
+/*
lng cpyval = i, inlen = 1;
cpyval /= qualifier2multiplier(ek);
@@ -4193,6 +4194,7 @@ interval_expression:
$$ = NULL;
YYABORT;
}
+*/
$$ = _newAtomNode( atom_int(SA, &t, i));
}
}
diff --git a/sql/test/snodgrass/Tests/cast_select.stable.out
b/sql/test/snodgrass/Tests/cast_select.stable.out
--- a/sql/test/snodgrass/Tests/cast_select.stable.out
+++ b/sql/test/snodgrass/Tests/cast_select.stable.out
@@ -56,7 +56,7 @@ SELECT CAST( TIME '12:34:56.123' AS TIME
+----------------+
| =_single_value |
+================+
-| false |
+| true |
+----------------+
1 row
@@ -64,7 +64,7 @@ SELECT CAST( TIMESTAMP '1997-07-23 12:34
+----------------+
| =_single_value |
+================+
-| true |
+| false |
+----------------+
1 row
@@ -128,7 +128,7 @@ SELECT CAST('2 12:34' AS INTERVAL DAY TO
+--------------+
| single_value |
+==============+
-| 218040 |
+| 218040.000 |
+--------------+
1 row
@@ -152,7 +152,7 @@ SELECT CAST( CAST( 7430400 AS INTERVAL S
+----------------+
1 row
-SELECT CAST(DATE '1997-01-01' AS CHARACTER) = '1997-01-01';
+SELECT CAST(DATE '1997-01-01' AS CHARACTER(10)) = '1997-01-01';
+----------------+
| =_single_value |
+================+
@@ -160,7 +160,7 @@ SELECT CAST(DATE '1997-01-01' AS CHARACT
+----------------+
1 row
-SELECT CAST(INTERVAL '7430400' SECOND AS INTEGER) = 7430400;
+SELECT CAST(INTERVAL '7430400' SECOND AS BIGINT) = 7430400000;
+----------------+
| =_single_value |
+================+
@@ -168,7 +168,7 @@ SELECT CAST(INTERVAL '7430400' SECOND AS
+----------------+
1 row
-SELECT CAST(CAST(INTERVAL '2064:00:00' HOUR TO SECOND AS INTERVAL SECOND) AS
INTEGER) = 7430400;
+SELECT CAST(CAST(INTERVAL '2064:00:00' HOUR TO SECOND AS INTERVAL SECOND) AS
BIGINT) = 7430400000;
+----------------+
| =_single_value |
+================+
diff --git a/sql/test/snodgrass/cast_select.sql
b/sql/test/snodgrass/cast_select.sql
--- a/sql/test/snodgrass/cast_select.sql
+++ b/sql/test/snodgrass/cast_select.sql
@@ -22,6 +22,6 @@ SELECT CAST('12:34' AS INTERVAL DAY TO M
SELECT CAST( INTERVAL'86 00:00:00' DAY TO SECOND AS INTERVAL HOUR TO SECOND )
= INTERVAL '2064:00:00' HOUR TO SECOND;
SELECT CAST('86 00:00:00' AS INTERVAL HOUR(3) TO SECOND ); -- err: overflow
exception
SELECT CAST( CAST( 7430400 AS INTERVAL SECOND ) AS INTERVAL DAY TO SECOND ) =
INTERVAL '86 00:00:00' DAY TO SECOND;
-SELECT CAST(DATE '1997-01-01' AS CHARACTER) = '1997-01-01';
-SELECT CAST(INTERVAL '7430400' SECOND AS INTEGER) = 7430400;
-SELECT CAST(CAST(INTERVAL '2064:00:00' HOUR TO SECOND AS INTERVAL SECOND) AS
INTEGER) = 7430400;
+SELECT CAST(DATE '1997-01-01' AS CHARACTER(10)) = '1997-01-01';
+SELECT CAST(INTERVAL '7430400' SECOND AS BIGINT) = 7430400000;
+SELECT CAST(CAST(INTERVAL '2064:00:00' HOUR TO SECOND AS INTERVAL SECOND) AS
BIGINT) = 7430400000;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list