1 SET TIME_ZONE =
"+00:00";
4 --echo #
Test of
errors for column data types that dont support
function
7 --error ER_INVALID_DEFAULT
8 eval CREATE
TABLE t1( a BIT DEFAULT $current_timestamp );
9 --error ER_INVALID_DEFAULT
10 eval CREATE
TABLE t1( a TINYINT DEFAULT $current_timestamp );
11 --error ER_INVALID_DEFAULT
12 eval CREATE
TABLE t1( a SMALLINT DEFAULT $current_timestamp );
13 --error ER_INVALID_DEFAULT
14 eval CREATE
TABLE t1( a MEDIUMINT DEFAULT $current_timestamp );
15 --error ER_INVALID_DEFAULT
16 eval CREATE
TABLE t1( a INT DEFAULT $current_timestamp );
17 --error ER_INVALID_DEFAULT
18 eval CREATE
TABLE t1( a BIGINT DEFAULT $current_timestamp );
19 --error ER_INVALID_DEFAULT
20 eval CREATE
TABLE t1( a FLOAT DEFAULT $current_timestamp );
21 --error ER_INVALID_DEFAULT
22 eval CREATE
TABLE t1( a DECIMAL DEFAULT $current_timestamp );
23 --error ER_INVALID_DEFAULT
24 eval CREATE
TABLE t1( a DATE DEFAULT $current_timestamp );
25 --error ER_INVALID_DEFAULT
26 eval CREATE
TABLE t1( a TIME DEFAULT $current_timestamp );
27 --error ER_INVALID_DEFAULT
28 eval CREATE
TABLE t1( a YEAR DEFAULT $current_timestamp );
30 --error ER_INVALID_ON_UPDATE
31 eval CREATE
TABLE t1( a BIT ON UPDATE $current_timestamp );
32 --error ER_INVALID_ON_UPDATE
33 eval CREATE
TABLE t1( a TINYINT ON UPDATE $current_timestamp );
34 --error ER_INVALID_ON_UPDATE
35 eval CREATE
TABLE t1( a SMALLINT ON UPDATE $current_timestamp );
36 --error ER_INVALID_ON_UPDATE
37 eval CREATE
TABLE t1( a MEDIUMINT ON UPDATE $current_timestamp );
38 --error ER_INVALID_ON_UPDATE
39 eval CREATE
TABLE t1( a INT ON UPDATE $current_timestamp );
40 --error ER_INVALID_ON_UPDATE
41 eval CREATE
TABLE t1( a BIGINT ON UPDATE $current_timestamp );
42 --error ER_INVALID_ON_UPDATE
43 eval CREATE
TABLE t1( a FLOAT ON UPDATE $current_timestamp );
44 --error ER_INVALID_ON_UPDATE
45 eval CREATE
TABLE t1( a DECIMAL ON UPDATE $current_timestamp );
46 --error ER_INVALID_ON_UPDATE
47 eval CREATE
TABLE t1( a DATE ON UPDATE $current_timestamp );
48 --error ER_INVALID_ON_UPDATE
49 eval CREATE
TABLE t1( a TIME ON UPDATE $current_timestamp );
50 --error ER_INVALID_ON_UPDATE
51 eval CREATE
TABLE t1( a YEAR ON UPDATE $current_timestamp );
54 --echo #
Test that the
default clause behaves like NOW() regarding time zones.
56 eval CREATE
TABLE t1 (
57 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
58 b $timestamp NOT NULL DEFAULT $current_timestamp,
59 c $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
61 e $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
62 f $datetime DEFAULT $current_timestamp,
63 g $datetime ON UPDATE $current_timestamp,
67 --echo # 2011-09-27 14:11:08 UTC
68 SET TIMESTAMP = 1317132668.654321;
69 SET @old_time_zone = @@TIME_ZONE;
70 SET TIME_ZONE =
"+05:00";
72 eval INSERT INTO t1( d, h ) VALUES ( $now, $now );
75 --echo
# 1989-05-13 01:02:03
76 SET TIMESTAMP = 611017323.543212;
77 eval UPDATE t1 SET d = $now, h = $now;
80 SET TIME_ZONE = @old_time_zone;
84 --echo #
Test of several TIMESTAMP columns with different
function defaults.
86 eval CREATE
TABLE t1 (
87 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
88 b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
89 c $timestamp NOT NULL DEFAULT $current_timestamp,
90 d $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
91 e $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
95 --echo # 2011-04-19 07:22:02 UTC
96 SET TIMESTAMP = 1303197722.534231;
98 INSERT INTO t1 ( f ) VALUES (1);
101 --echo
# 2011-04-19 07:23:18 UTC
102 SET TIMESTAMP = 1303197798.132435;
110 --echo #
Test of inserted values out of order.
112 eval CREATE
TABLE t1 (
114 b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
115 c $timestamp NOT NULL DEFAULT $current_timestamp,
116 d $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
119 g $datetime DEFAULT $current_timestamp,
120 h $datetime ON UPDATE $current_timestamp,
121 i $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
125 --echo # 2011-04-19 07:22:02 UTC
126 SET TIMESTAMP = 1303197722.534231;
128 INSERT INTO t1 ( j, a ) VALUES ( 1, 1 );
134 --echo #
Test of ON DUPLICATE
KEY UPDATE
136 eval CREATE
TABLE t1 (
139 c $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
140 d $timestamp NOT NULL DEFAULT $current_timestamp,
141 e $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
142 f $timestamp NOT NULL DEFAULT
'1986-09-27 03:00:00.098765',
144 h $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
145 i $datetime DEFAULT $current_timestamp,
146 j $datetime ON UPDATE $current_timestamp,
148 l $datetime DEFAULT
'1986-09-27 03:00:00.098765'
151 --echo # 1977-12-21 23:00:00 UTC
152 SET TIMESTAMP = 251593200.192837;
153 INSERT INTO t1(a) VALUES (1) ON DUPLICATE
KEY UPDATE b = 2;
156 --echo
# 1975-05-21 23:00:00 UTC
157 SET TIMESTAMP = 169945200.918273;
158 INSERT INTO t1(a) VALUES (1) ON DUPLICATE
KEY UPDATE b = 2;
161 --echo
# 1973-08-14 09:11:22 UTC
162 SET TIMESTAMP = 114167482.534231;
163 INSERT INTO t1(a) VALUES (2) ON DUPLICATE
KEY UPDATE b = 2;
168 eval CREATE
TABLE t1 ( a INT PRIMARY
KEY, b INT, c $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp );
170 --echo
# 2011-04-19 07:23:18 UTC
171 SET TIMESTAMP = 1303197798.945156;
173 INSERT INTO t1 VALUES
174 (1, 0,
'2001-01-01 01:01:01.111111'),
175 (2, 0,
'2002-02-02 02:02:02.222222'),
176 (3, 0,
'2003-03-03 03:03:03.333333');
179 UPDATE t1 SET b = 2, c = c WHERE a = 2;
182 INSERT INTO t1 (a) VALUES (4);
185 UPDATE t1 SET c = '2004-04-04 04:04:04.444444' WHERE a = 4;
188 INSERT INTO t1 ( a ) VALUES ( 3 ), ( 5 ) ON DUPLICATE KEY UPDATE b = 3, c = c;
191 INSERT INTO t1 (a, c) VALUES
192 (4, '2004-04-04 00:00:00.444444'),
193 (6, '2006-06-06 06:06:06.666666')
194 ON DUPLICATE KEY UPDATE b = 4;
204 eval CREATE
TABLE t1 (
206 b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
207 c $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
208 d $timestamp NOT NULL DEFAULT $current_timestamp,
209 e $datetime DEFAULT $current_timestamp,
210 f $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
211 g $datetime ON UPDATE $current_timestamp,
216 --echo # 1970-09-21 09:11:12 UTC
217 SET TIMESTAMP = 22756272.163584;
219 REPLACE INTO t1 ( a ) VALUES ( 1 );
222 --echo
# 1970-11-10 14:16:17 UTC
223 SET TIMESTAMP = 27094577.852954;
226 REPLACE INTO t1 ( a ) VALUES ( 1 );
233 --echo #
Test of insertion of NULL, DEFAULT and an empty row
for DEFAULT
234 --echo # CURRENT_TIMESTAMP.
236 eval CREATE
TABLE t1 (
237 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
238 b $datetime DEFAULT $current_timestamp,
242 --echo # 2011-04-20 09:53:41 UTC
243 SET TIMESTAMP = 1303293221.163578;
245 INSERT INTO t1 VALUES (NULL, NULL, 1), (DEFAULT, DEFAULT, 2);
246 INSERT INTO t1 ( a, b, c ) VALUES (NULL, NULL, 3), (DEFAULT, DEFAULT, 4);
249 SET TIME_ZONE = "+03:00";
251 SET TIME_ZONE = "+00:00";
255 --echo
# 2011-04-20 07:05:39 UTC
256 SET TIMESTAMP = 1303283139.195624;
257 eval CREATE
TABLE t1 (
258 a $timestamp NOT NULL DEFAULT
'2010-10-11 12:34:56' ON UPDATE $current_timestamp,
259 b $datetime DEFAULT
'2010-10-11 12:34:56'
262 INSERT INTO t1 VALUES (NULL, NULL), (DEFAULT, DEFAULT);
263 INSERT INTO t1 ( a, b ) VALUES (NULL, NULL), (DEFAULT, DEFAULT);
268 --echo
# 2011-04-20 09:53:41 UTC
269 SET TIMESTAMP = 1303293221.136952;
271 eval CREATE
TABLE t1 (
272 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
273 b $timestamp NOT NULL DEFAULT $current_timestamp,
274 c $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
275 d $timestamp NOT NULL DEFAULT
'1986-09-27 03:00:00.098765',
277 f $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
278 g $datetime DEFAULT $current_timestamp,
279 h $datetime ON UPDATE $current_timestamp,
281 j $datetime DEFAULT
'1986-09-27 03:00:00.098765'
284 INSERT INTO t1 VALUES ();
286 INSERT INTO t1 SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL;
293 --echo #
Test of multiple-
table UPDATE
for DEFAULT CURRENT_TIMESTAMP
295 eval CREATE
TABLE t1 (
296 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
297 b $datetime DEFAULT $current_timestamp,
301 INSERT INTO t1 ( c ) VALUES (1);
304 --echo
# 2011-04-20 17:06:13 UTC
305 SET TIMESTAMP = 1303311973.163587;
307 UPDATE t1 t11, t1 t12 SET t11.c = 1;
310 UPDATE t1 t11, t1 t12 SET t11.c = 2;
316 eval CREATE
TABLE t1 (
317 a $timestamp NOT NULL DEFAULT $current_timestamp,
318 b $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
319 c $datetime DEFAULT $current_timestamp,
320 d $datetime ON UPDATE $current_timestamp,
324 eval CREATE
TABLE t2 (
326 g $datetime ON UPDATE $current_timestamp,
327 h $datetime DEFAULT $current_timestamp,
328 i $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
329 j $timestamp NOT NULL DEFAULT $current_timestamp
332 --echo # 1995-03-11 00:02:03 UTC
333 SET TIMESTAMP = 794880123.195676;
335 INSERT INTO t1 ( e ) VALUES ( 1 ), ( 2 );
337 INSERT INTO t2 ( f ) VALUES ( 1 ), ( 2 );
342 --echo
# 1980-12-13 02:02:01 UTC
343 SET TIMESTAMP = 345520921.196755;
345 UPDATE t1, t2 SET t1.e = 3, t2.f = 4;
353 --echo #
Test of multiple
table update with temporary
table and on the fly.
355 eval CREATE
TABLE t1 (
356 a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
357 b $datetime ON UPDATE $current_timestamp,
362 eval CREATE
TABLE t2 (
363 a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
364 b $datetime ON UPDATE $current_timestamp,
369 INSERT INTO t1 ( c ) VALUES (1), (2);
370 INSERT INTO t2 ( c ) VALUES (1), (2);
372 --echo
# Test of multiple table update done on the fly
373 --echo # 2011-04-20 15:06:13 UTC
374 SET TIMESTAMP = 1303311973.194685;
375 UPDATE t1
JOIN t2 USING ( c ) SET t2.d = 1;
379 --echo
# Test of multiple table update done with temporary table.
380 --echo # 1979-01-15 03:02:01
381 SET TIMESTAMP = 285213721.134679;
382 UPDATE t1
JOIN t2 USING ( c ) SET t1.d = 1;
390 --echo #
Test of ON UPDATE CURRENT_TIMESTAMP.
392 eval CREATE
TABLE t1 (
393 a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
394 b $datetime ON UPDATE $current_timestamp,
398 --echo # 2011-04-20 09:53:41 UTC
399 SET TIMESTAMP = 1303293221.794613;
401 INSERT INTO t1 ( c ) VALUES ( 1 );
411 --echo #
Test of multiple-
table UPDATE
for ON UPDATE CURRENT_TIMESTAMP
413 --echo # 2011-04-20 15:06:13 UTC
414 SET TIMESTAMP = 1303311973.534231;
416 UPDATE t1 t11, t1 t12 SET t11.c = 2;
419 UPDATE t1 t11, t1 t12 SET t11.c = 3;
425 --echo #
Test of a multiple-
table update where only one
table is updated and
426 --echo # the updated
table has a primary key.
428 eval CREATE
TABLE t1 ( a INT, b INT, PRIMARY KEY (a) );
429 INSERT INTO t1 VALUES (1, 1),(2, 2),(3, 3),(4, 4);
431 eval CREATE
TABLE t2 ( a INT, b INT );
432 INSERT INTO t2 VALUES (1, 1),(2, 2),(3, 3),(4, 4),(5, 5);
434 UPDATE t1, t2 SET t1.b = 100 WHERE t1.a = t2.a;
442 --echo #
Test of ALTER
TABLE, reordering columns.
444 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp, b INT );eval ALTER TABLE t1 MODIFY a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp AFTER b;
445 SHOW CREATE TABLE t1;
448 eval CREATE TABLE t1 ( a INT, b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp, c $timestamp NULL );eval ALTER TABLE t1 MODIFY b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp FIRST;
449 SHOW CREATE TABLE t1;
452 eval CREATE TABLE t1 ( a INT, b $timestamp NULL );eval ALTER TABLE t1 MODIFY b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp FIRST;
453 SHOW CREATE TABLE t1;
456 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp, b $timestamp NULL );eval ALTER TABLE t1 MODIFY a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' AFTER b;
457 SHOW CREATE TABLE t1;
460 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp, b $timestamp NULL );eval ALTER TABLE t1 MODIFY a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' AFTER b;
461 SHOW CREATE TABLE t1;
464 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $now, b INT, c $timestamp NULL );
465 SHOW CREATE TABLE t1;eval ALTER TABLE t1 MODIFY a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp AFTER b;
466 SHOW CREATE TABLE t1;
469 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $now, b INT, c $timestamp NULL );eval ALTER TABLE t1 MODIFY c $timestamp NULL FIRST;
470 SHOW CREATE TABLE t1;
473 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT $now ON UPDATE $current_timestamp, b INT, c $timestamp NULL );
474 SHOW CREATE TABLE t1;eval ALTER TABLE t1 MODIFY a $timestamp NOT NULL DEFAULT $now ON UPDATE $current_timestamp AFTER b;
475 SHOW CREATE TABLE t1;
478 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT $now ON UPDATE $current_timestamp, b INT, c $timestamp NULL );eval ALTER TABLE t1 MODIFY c $timestamp NULL FIRST;
479 SHOW CREATE TABLE t1;
484 --echo #
Test of ALTER TABLE, adding columns.
486 eval CREATE TABLE t1 ( a INT );
487 eval ALTER TABLE t1 ADD COLUMN b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp;
488 SHOW CREATE TABLE t1;
492 --echo #
Test of INSERT SELECT.
494 eval CREATE TABLE t1 (
495 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
496 b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
497 c $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
498 d $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp
501 eval CREATE TABLE t2 (
506 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
507 b $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00',
512 --echo # 1977-08-16 15:30:01 UTC
513 SET TIMESTAMP = 240589801.654312;
515 INSERT INTO t2 (a, b, c, d) VALUES (
516 '1977-08-16 15:30:01.123456',
517 '1977-08-16 15:30:01.234567',
518 '1977-08-16 15:30:01.345678',
519 '1977-08-16 15:30:01.456789'
522 --echo
# 1986-09-27 01:00:00 UTC
523 SET TIMESTAMP = 528166800.132435;
525 INSERT INTO t1 ( a, c ) SELECT a, c FROM t2;
532 --echo #
Test of CREATE TABLE SELECT.
534 --echo # We
test that the columns of the source
table are used
to determine
535 --echo #
function defaults
for the receiving
table.
538 --echo # 1970-04-11 20:13:57 UTC
539 SET TIMESTAMP = 8712837.657898;
540 eval CREATE TABLE t1 (
541 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
542 b $timestamp NOT NULL DEFAULT $current_timestamp,
543 c $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
544 d $timestamp NOT NULL DEFAULT
'1986-09-27 03:00:00.098765',
546 f $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
547 g $datetime DEFAULT $current_timestamp,
548 h $datetime ON UPDATE $current_timestamp,
550 j $datetime DEFAULT
'1986-09-27 03:00:00.098765'
553 INSERT INTO t1 VALUES ();
555 --echo # 1971-01-31 21:13:57 UTC
556 SET TIMESTAMP = 34200837.164937;
558 eval CREATE TABLE t2 SELECT a FROM t1; SHOW CREATE TABLE t2; SELECT * FROM t2;
559 eval CREATE TABLE t3 SELECT b FROM t1; SHOW CREATE TABLE t3; SELECT * FROM t3;
560 eval CREATE TABLE t4 SELECT c FROM t1; SHOW CREATE TABLE t4; SELECT * FROM t4;
561 eval CREATE TABLE t5 SELECT d FROM t1; SHOW CREATE TABLE t5; SELECT * FROM t5;
562 eval CREATE TABLE t6 SELECT e FROM t1; SHOW CREATE TABLE t6; SELECT * FROM t6;
563 eval CREATE TABLE t7 SELECT f FROM t1; SHOW CREATE TABLE t7; SELECT * FROM t7;
564 eval CREATE TABLE t8 SELECT g FROM t1; SHOW CREATE TABLE t8; SELECT * FROM t8;
565 eval CREATE TABLE t9 SELECT h FROM t1; SHOW CREATE TABLE t9; SELECT * FROM t9;
566 eval CREATE TABLE t10 SELECT
i FROM t1; SHOW CREATE TABLE t10; SELECT * FROM t10;
567 eval CREATE TABLE t11 SELECT j FROM t1; SHOW CREATE TABLE t11; SELECT * FROM t11;
569 eval CREATE TABLE t12 (
570 k $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
571 l $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
572 m $timestamp NOT NULL DEFAULT $current_timestamp,
573 n $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
574 o $timestamp NOT NULL DEFAULT
'1986-09-27 03:00:00.098765',
576 q $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
577 r $datetime DEFAULT $current_timestamp,
578 s $datetime ON UPDATE $current_timestamp,
580 u $datetime DEFAULT
'1986-09-27 03:00:00.098765'
584 SHOW CREATE TABLE t12;
586 --echo # No
function default for non-column expressions:
587 eval CREATE TABLE t13 SELECT COALESCE(a,a) FROM t1; SHOW CREATE TABLE t13; SELECT * FROM t13;
589 DROP TABLE t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13;
591 --echo
# 1970-04-11 20:13:57 UTC
592 SET TIMESTAMP = 8712837.164953;
593 eval CREATE TABLE t1 (
594 a $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp,
595 b $datetime DEFAULT $current_timestamp,
596 c $datetime ON UPDATE $current_timestamp,
598 e $datetime DEFAULT
'1986-09-27 03:00:00.098765'
601 INSERT INTO t1 VALUES ();
603 --echo # 1971-01-31 20:13:57 UTC
604 SET TIMESTAMP = 34200837.915736;
606 eval CREATE TABLE t2 SELECT a FROM t1;
607 SHOW CREATE TABLE t2;
610 eval CREATE TABLE t3 SELECT b FROM t1;
611 SHOW CREATE TABLE t3;
614 eval CREATE TABLE t4 SELECT c FROM t1;
615 SHOW CREATE TABLE t4;
618 eval CREATE TABLE t5 SELECT d FROM t1;
619 SHOW CREATE TABLE t5;
622 eval CREATE TABLE t6 SELECT e FROM t1;
623 SHOW CREATE TABLE t6;
626 --echo #
Test CREATE TABLE LIKE
627 CREATE TABLE t7 LIKE t1;
628 SHOW CREATE TABLE t7;
630 DROP TABLE t1, t2, t3, t4, t5, t6, t7;
633 --echo #
Test of a CREATE TABLE SELECT that also declared columns. In
this case
634 --echo # the
function default for them should be activated during the execution of the
637 --echo # 1970-01-01 03:16:40
638 SET TIMESTAMP = 1000.987654;
639 eval CREATE TABLE t1 ( a INT );
640 INSERT INTO t1 VALUES ( 1 ), ( 2 );
642 eval CREATE TABLE t2 ( b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp) SELECT a FROM t1;
644 SHOW CREATE TABLE t2;
645 SET TIMESTAMP = 2000.876543;
646 INSERT INTO t2( a ) VALUES ( 3 );
654 eval CREATE TABLE t1 ( a INT, b $datetime DEFAULT $current_timestamp );
655 eval CREATE TABLE t2 ( a INT, b $datetime ON UPDATE $current_timestamp );
657 eval CREATE VIEW v1 AS SELECT * FROM t1;
660 eval CREATE VIEW v2 AS SELECT * FROM t2;
663 --echo # 1971-01-31 21:13:57 UTC
664 SET TIMESTAMP = 34200837.348564;
666 INSERT INTO v1 ( a ) VALUES ( 1 );
667 INSERT INTO v2 ( a ) VALUES ( 1 );
675 --echo
# 1970-04-11 20:13:57 UTC
676 SET TIMESTAMP = 8712837.567332;
690 --echo #
Test with stored procedures.
692 eval CREATE TABLE t1 (
694 b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
695 c $timestamp NOT NULL DEFAULT $current_timestamp,
696 d $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
698 f $datetime DEFAULT $current_timestamp,
699 g $datetime ON UPDATE $current_timestamp
701 CREATE PROCEDURE p1() INSERT INTO
test.t1( a ) VALUES ( 1 );
702 CREATE PROCEDURE p2() UPDATE t1 SET a = 2 WHERE a = 1;
704 --echo
# 1971-01-31 20:13:57 UTC
705 SET TIMESTAMP = 34200837.876544;
709 --echo # 1970-04-11 21:13:57 UTC
710 SET TIMESTAMP = 8712837.143546;
719 --echo #
Test with triggers.
721 eval CREATE TABLE t1 (
723 b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
724 c $timestamp NOT NULL DEFAULT $current_timestamp,
725 d $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
728 g $datetime DEFAULT $current_timestamp,
729 h $datetime ON UPDATE $current_timestamp,
730 i $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp
733 eval CREATE TABLE t2 ( a INT );
736 eval CREATE TRIGGER t2_trg BEFORE INSERT ON t2 FOR EACH ROW
738 INSERT INTO t1 ( a ) VALUES ( 1 );
742 --echo
# 1971-01-31 21:13:57 UTC
743 SET TIMESTAMP = 34200837.978675;
745 INSERT INTO t2 ( a ) VALUES ( 1 );
751 eval CREATE TRIGGER t2_trg BEFORE INSERT ON t2 FOR EACH ROW
757 --echo
# 1970-04-11 21:13:57 UTC
758 SET TIMESTAMP = 8712837.456789;
760 INSERT INTO t2 ( a ) VALUES ( 1 );
766 --echo #
Test where the assignment target is not a column.
768 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp );
769 eval CREATE TABLE t2 ( a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp );
770 eval CREATE TABLE t3 ( a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp );
771 eval CREATE TABLE t4 ( a $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp );
773 eval CREATE VIEW v1 AS SELECT a COLLATE latin1_german1_ci AS b FROM t1;
774 eval CREATE VIEW v2 ( b ) AS SELECT a COLLATE latin1_german1_ci FROM t2;
775 eval CREATE VIEW v3 AS SELECT a COLLATE latin1_german1_ci AS b FROM t3;
776 eval CREATE VIEW v4 ( b ) AS SELECT a COLLATE latin1_german1_ci FROM t4;
778 INSERT INTO v1 ( b ) VALUES ( '2007-10-24 00:03:34.010203' );
781 INSERT INTO v2 ( b ) VALUES ( '2007-10-24 00:03:34.010203' );
784 INSERT INTO t3 VALUES ();
785 UPDATE v3 SET b = '2007-10-24 00:03:34.010203';
788 INSERT INTO t4 VALUES ();
789 UPDATE v4 SET b = '2007-10-24 00:03:34.010203';
792 DROP VIEW v1, v2, v3, v4;
793 DROP TABLE t1, t2, t3, t4;
796 --echo #
Test of LOAD DATA/XML INFILE
797 --echo # This tests behavior of
function defaults
for TIMESTAMP and DATETIME
798 --echo # columns. during LOAD ... INFILE.
799 --echo # As can be seen here, a TIMESTAMP column with only ON UPDATE
800 --echo # CURRENT_TIMESTAMP will still have CURRENT_TIMESTAMP inserted on LOAD
801 --echo # ... INFILE
if the value is missing. For DATETIME columns a NULL value
802 --echo # is inserted instead.
805 eval CREATE TABLE t1 (
807 b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
808 c $timestamp NOT NULL DEFAULT $current_timestamp,
809 d $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
810 e $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
812 g $datetime DEFAULT $current_timestamp,
813 h $datetime ON UPDATE $current_timestamp,
814 i $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp
817 eval CREATE TABLE t2 (
818 a $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
819 b $timestamp NOT NULL DEFAULT $current_timestamp,
820 c $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $current_timestamp,
821 d $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
822 e $datetime NOT NULL,
823 f $datetime NOT NULL DEFAULT
'1977-01-02 12:13:14',
824 g $datetime DEFAULT $current_timestamp NOT NULL,
825 h $datetime ON UPDATE $current_timestamp NOT NULL,
826 i $datetime DEFAULT $current_timestamp ON UPDATE $current_timestamp NOT NULL
829 SELECT 1 INTO OUTFILE
't3.dat' FROM dual;
831 SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
832 INTO OUTFILE
't4.dat'
835 SELECT 1, 2 INTO OUTFILE
't5.dat' FROM dual;
837 --echo # Mon Aug 1 15:11:19 2011 UTC
838 SET TIMESTAMP = 1312211479.918273;
840 LOAD DATA INFILE
't3.dat' INTO TABLE t1;
841 --query_vertical SELECT * FROM t1
843 LOAD DATA INFILE
't4.dat' INTO TABLE t2;
848 --echo # As shown here, supplying a NULL value
to a non-nullable
849 --echo # column with no
default value results in the zero date.
851 --echo # As shown here, supplying a NULL value
to a non-nullable column with a
852 --echo #
default value results in the zero date.
854 --echo # As shown here, supplying a NULL value
to a non-nullable column with a
855 --echo #
default function results in the zero date.
857 --echo # As shown here, supplying a NULL value
to a non-nullable DATETIME ON
858 --echo # UPDATE CURRENT_TIMESTAMP column with no
default value results in the
866 --echo # Read t3
file into t1
867 --echo # The syntax will cause a different
code path
to be taken
868 --echo # (read_fixed_length()) than under the LOAD ... INTO TABLE t1 command
869 --echo # above. The
code in
this path is copy-pasted
code from the path taken
870 --echo # under the syntax used in the previous LOAD command.
871 LOAD DATA INFILE
't3.dat' INTO TABLE t1
872 FIELDS TERMINATED BY
'' ENCLOSED BY
'';
878 --echo # Yes, a missing field cannot be NULL
using this syntax, so it will
879 --echo # zero date instead. Says a comment in read_fixed_length() :
"No fields
880 --echo # specified in fields_vars list can be NULL in this format."
881 --echo # It appears
to be by design. This is inconsistent with LOAD DATA INFILE
882 --echo # syntax in previous
test.
885 --echo # See comment above
"SELECT f FROM f1".
890 LOAD DATA INFILE
't5.dat' INTO TABLE t1 ( a, @dummy );
895 LOAD DATA INFILE
't3.dat' INTO TABLE t1 ( a ) SET c = '2005-06-06 08:09:10';
899 LOAD DATA INFILE 't3.dat' INTO TABLE t1 ( a ) SET g = '2005-06-06 08:09:10';
903 --echo
# Load a static XML file
904 LOAD XML INFILE
'../../std_data/onerow.xml' INTO TABLE t1
905 ROWS IDENTIFIED BY
'<row>';
907 --echo Missing tags are treated as NULL
908 --query_vertical SELECT * FROM t1
912 let $MYSQLD_DATADIR= `select @@datadir`;
913 remove_file $MYSQLD_DATADIR/
test/t3.dat;
914 remove_file $MYSQLD_DATADIR/
test/t4.dat;
915 remove_file $MYSQLD_DATADIR/
test/t5.dat;
919 --echo # Similar LOAD DATA tests in another
form
921 --echo # All of
this test portion has been
run on a pre-WL5874 trunk
922 --echo # (except that like_b and like_c didn
't exist) and all result
923 --echo # differences are a bug.
924 --echo # Regarding like_b its definition is the same as b's except
925 --echo # that the constant
default is replaced with a
function
926 --echo #
default. Our expectation is that like_b would behave
927 --echo # like b:
if b is
set to NULL, or
set to 0000-00-00, or
set to
928 --echo # its
default, then the same should apply to like_b. Same
for
929 --echo # like_c vs c.
931 --echo # Mon Aug 1 15:11:19 2011 UTC
932 SET TIMESTAMP = 1312211479.089786;
934 SELECT 1 INTO OUTFILE
"file1.dat" FROM dual;
935 SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
936 INTO OUTFILE
"file2.dat" FROM dual;
938 --echo # Too
short row
943 a $datetime NULL DEFAULT NULL,
944 b $datetime NULL DEFAULT
"2011-11-18",
945 like_b $datetime NULL DEFAULT $current_timestamp,
946 c $datetime NOT NULL DEFAULT
"2011-11-18",
947 like_c $datetime NOT NULL DEFAULT $current_timestamp,
948 d $timestamp NULL DEFAULT
"2011-05-03" ON UPDATE $current_timestamp,
949 e $timestamp NOT NULL DEFAULT
"2011-05-03",
950 f $timestamp NOT NULL DEFAULT $current_timestamp,
951 g $timestamp NULL DEFAULT NULL,
953 i INT NOT NULL DEFAULT 42
956 --echo # There is no promotion
957 SHOW CREATE TABLE t1;
959 LOAD DATA INFILE
"file1.dat" INTO
table t1;
961 --echo # It is strange that
"like_b" gets NULL when
"b" gets 0. But
962 --echo #
this is consistent with how
"a" gets NULL when
"b" gets 0,
963 --echo # with how
"g" gets NULL when
"d" gets 0, and with how
"h" gets
964 --echo # NULL when
"i" gets 0. Looks like
"DEFAULT
965 --echo # <non-NULL-constant>" is changed to 0, whereas DEFAULT NULL
966 --echo # and DEFAULT NOW are changed to NULL.
967 --query_vertical SELECT * FROM t1
971 modify f TIMESTAMP NULL
default CURRENT_TIMESTAMP;
973 --echo # There is no promotion
974 SHOW CREATE TABLE t1;
976 LOAD DATA INFILE
"file1.dat" INTO
table t1;
978 --query_vertical SELECT * FROM t1
983 --echo # Conclusion derived from trunk
's results:
984 --echo # DATETIME DEFAULT <non-NULL-constant> (b,c) gets 0000-00-00,
985 --echo # DATETIME DEFAULT NULL (a) gets NULL,
986 --echo # TIMESTAMP NULL DEFAULT <non-NULL-constant> (d) gets 0000-00-00,
987 --echo # TIMESTAMP NULL DEFAULT NULL (g) gets NULL,
988 --echo # TIMESTAMP NULL DEFAULT NOW (f after ALTER) gets NULL,
989 --echo # TIMESTAMP NOT NULL (f before ALTER, e) gets NOW.
991 --echo ### Loading NULL ###
996 a $datetime NULL DEFAULT NULL,
997 b $datetime NULL DEFAULT "2011-11-18",
998 like_b $datetime NULL DEFAULT $current_timestamp,
999 c $datetime NOT NULL DEFAULT "2011-11-18",
1000 like_c $datetime NOT NULL DEFAULT $current_timestamp,
1001 d $timestamp NULL DEFAULT "2011-05-03" ON UPDATE $current_timestamp,
1002 e $timestamp NOT NULL DEFAULT "2011-05-03",
1003 f $timestamp NOT NULL DEFAULT $current_timestamp,
1004 g $timestamp NULL DEFAULT NULL,
1006 i INT NOT NULL DEFAULT 42
1009 --echo # There is no promotion
1010 SHOW CREATE TABLE t1;
1012 LOAD DATA INFILE "file2.dat" INTO table t1;
1014 --query_vertical SELECT * FROM t1
1018 modify f TIMESTAMP NULL default CURRENT_TIMESTAMP;
1020 --echo # There is no promotion
1021 SHOW CREATE TABLE t1;
1023 LOAD DATA INFILE "file2.dat" INTO table t1;
1025 --query_vertical SELECT * FROM t1
1028 --echo # Conclusion derived from trunk's results:
1029 --echo # DATETIME NULL (a,b) gets NULL,
1030 --echo
# DATETIME NOT NULL (c) gets 0000-00-00,
1031 --echo # TIMESTAMP NULL (d,f,g) gets NULL,
1032 --echo
# TIMESTAMP NOT NULL (e) gets NOW.
1035 remove_file $MYSQLD_DATADIR/
test/file1.dat;
1036 remove_file $MYSQLD_DATADIR/
test/file2.dat;
1039 --echo #
Test of updatable views with check options. The
option can be violated
1040 --echo #
using ON UPDATE updates which is very strange as
this offers a loophole
1041 --echo # in
this integrity check.
1043 SET TIME_ZONE =
"+03:00";
1044 --echo # 1970-01-01 03:16:40
1045 SET TIMESTAMP = 1000.123456;
1047 eval CREATE TABLE t1 ( a INT, b $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp);
1049 SHOW CREATE TABLE t1;
1051 INSERT INTO t1 ( a ) VALUES ( 1 );
1055 eval CREATE VIEW v1 AS SELECT * FROM t1 WHERE b <= '1970-01-01 03:16:40.123456'
1060 --echo
# 1970-01-01 03:33:20
1061 SET TIMESTAMP = 2000.000234;
1063 --echo Logically, there should be an ER_VIEW_CHECK_FAILED here.
1064 UPDATE v1 SET a = 2;
1070 eval CREATE TABLE t1 (
1071 a $timestamp NOT NULL DEFAULT
'1973-08-14 09:11:22.089786' ON UPDATE $current_timestamp,
1074 --echo # 1973-08-14 09:11:22 UTC
1075 SET TIMESTAMP = 114167482.534231;
1076 INSERT INTO t1 ( c ) VALUES ( 1 );
1078 eval CREATE VIEW v1 AS
1081 WHERE a >= '1973-08-14 09:11:22'
1082 WITH LOCAL CHECK OPTION;
1086 SET TIMESTAMP = 1.126789;
1088 --echo Logically, there should be an ER_VIEW_CHECK_FAILED here.
1089 INSERT INTO v1 ( c ) VALUES ( 1 ) ON DUPLICATE KEY UPDATE c = 2;
1097 --echo # Bug 13095459 - MULTI-TABLE UPDATE MODIFIES
A ROW TWICE
1099 eval CREATE TABLE t1 (
1102 ts $timestamp NOT NULL DEFAULT $current_timestamp ON UPDATE $current_timestamp,
1103 PRIMARY KEY ( a, ts )
1105 INSERT INTO t1( a, b, ts ) VALUES ( 1, 0, '2000-09-28 17:44:34' );
1107 CREATE TABLE t2 ( a INT );
1108 INSERT INTO t2 VALUES ( 1 );
1110 UPDATE t1 STRAIGHT_JOIN t2
1112 WHERE t1.a = 1 AND t1.ts >= '2000-09-28 00:00:00';
1119 --echo # Bug#11745578: 17392: ALTER TABLE ADD COLUMN TIMESTAMP DEFAULT
1120 --echo # CURRENT_TIMESTAMP INSERTS ZERO
1122 SET timestamp = 1000;
1124 CREATE TABLE t1 ( b INT );
1125 INSERT INTO t1 VALUES (1),(2);
1127 eval ALTER TABLE t1 ADD COLUMN a6 $datetime DEFAULT $now ON UPDATE $now FIRST;
1128 eval ALTER TABLE t1 ADD COLUMN a5 $datetime DEFAULT $now FIRST;
1129 eval ALTER TABLE t1 ADD COLUMN a4 $datetime ON UPDATE $now FIRST;
1131 eval ALTER TABLE t1 ADD COLUMN a3 $timestamp NOT NULL DEFAULT $now ON UPDATE $now FIRST;
1132 eval ALTER TABLE t1 ADD COLUMN a2 $timestamp NOT NULL DEFAULT $now FIRST;
1133 eval ALTER TABLE t1 ADD COLUMN a1 $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $now FIRST;
1135 eval ALTER TABLE t1 ADD COLUMN c1 $timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00' ON UPDATE $now AFTER b;
1136 eval ALTER TABLE t1 ADD COLUMN c2 $timestamp NOT NULL DEFAULT $now AFTER c1;
1137 eval ALTER TABLE t1 ADD COLUMN c3 $timestamp NOT NULL DEFAULT $now ON UPDATE $now AFTER c2;
1139 eval ALTER TABLE t1 ADD COLUMN c4 $datetime ON UPDATE $now AFTER c3;
1140 eval ALTER TABLE t1 ADD COLUMN c5 $datetime DEFAULT $now AFTER c4;
1141 eval ALTER TABLE t1 ADD COLUMN c6 $datetime DEFAULT $now ON UPDATE $now AFTER c5;
1148 eval CREATE TABLE t1 ( a $timestamp NOT NULL DEFAULT $now ON UPDATE $current_timestamp, b $datetime DEFAULT $now );
1149 INSERT INTO t1 VALUES ();
1151 SET timestamp = 1000000000;
1153 ALTER TABLE t1 MODIFY COLUMN a TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3);
1154 ALTER TABLE t1 MODIFY COLUMN b DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3);
1161 eval CREATE TABLE t1 (
1162 a $timestamp NOT NULL DEFAULT '1999-12-01 11:22:33' ON UPDATE $current_timestamp,
1163 b $datetime DEFAULT '1999-12-01 11:22:33'
1165 INSERT INTO t1 VALUES ();
1167 eval ALTER TABLE t1 MODIFY COLUMN a $timestamp DEFAULT $now;
1168 eval ALTER TABLE t1 MODIFY COLUMN b $datetime DEFAULT $now;
1169 INSERT INTO t1 VALUES ();