1717
1818namespace Example ;
1919
20+ use DateTime ;
2021use MonetDB \Connection ;
2122
2223
@@ -34,7 +35,8 @@ public function Run(array $args) {
3435 "weight_kg" decimal(8, 2),
3536 "category" text,
3637 "birth_date" date,
37- "net_worth_usd" decimal(20, 4)
38+ "net_worth_usd" decimal(20, 4),
39+ "created" timestamp
3840 );
3941 ' );
4042
@@ -44,28 +46,30 @@ public function Run(array $args) {
4446
4547 /* *** */
4648
49+ $ now = date ("Y-m-d H:i:s.u " );
50+
4751 $ result = $ connection ->Query (<<<EOF
4852 start transaction;
4953
5054 insert into
5155 "cats"
52- ("name", "weight_kg", "category", "birth_date", "net_worth_usd")
56+ ("name", "weight_kg", "category", "birth_date", "net_worth_usd", "created" )
5357 values
54- ('Tiger', 8.2, 'fluffy', '2012-04-23', 2340000),
55- ('Oscar', 3.4, 'spotted', '2014-02-11', 556235.34),
56- ('Coco', 2.52, 'spotted', '2008-12-31', 1470500000),
57- ('Max', 4.23, 'spotted', '2010-01-15', 100),
58- ('Sooty', 7.2, 'shorthair', '2016-10-01', 580000),
59- ('Milo', 5.87, 'spotted', '2015-06-23', 1500.53),
60- ('Muffin', 12.6, 'fluffy', '2013-04-07', 230000),
61- ('Ginger', 9.4, 'shorthair', '2012-06-19', 177240.5),
62- ('Fluffor', 13.12, 'fluffy', '2000-10-07', 5730180200.12),
63- ('Lucy', 3.12, 'shorthair', '2018-06-29', 5780000),
64- ('Chloe', 2.12, 'spotted', '2013-05-01', 13666200),
65- ('Misty', 1.96, 'shorthair', '2014-11-24', 12000000),
66- ('Sam', 3.45, 'fluffy', '2018-12-19', 580.4),
67- ('Gizmo', 4.65, 'fluffy', '2016-05-11', 120300),
68- ('Kimba', 1.23, 'spotted', '2020-01-08', 890000);
58+ ('Tiger', 8.2, 'fluffy', '2012-04-23', 2340000, timestamp ' { $ now } ' ),
59+ ('Oscar', 3.4, 'spotted', '2014-02-11', 556235.34, timestamp ' { $ now } ' ),
60+ ('Coco', 2.52, 'spotted', '2008-12-31', 1470500000, timestamp ' { $ now } ' ),
61+ ('Max', 4.23, 'spotted', '2010-01-15', 100, timestamp ' { $ now } ' ),
62+ ('Sooty', 7.2, 'shorthair', '2016-10-01', 580000, timestamp ' { $ now } ' ),
63+ ('Milo', 5.87, 'spotted', '2015-06-23', 1500.53, timestamp ' { $ now } ' ),
64+ ('Muffin', 12.6, 'fluffy', '2013-04-07', 230000, timestamp ' { $ now } ' ),
65+ ('Ginger', 9.4, 'shorthair', '2012-06-19', 177240.5, timestamp ' { $ now } ' ),
66+ ('Fluffor', 13.12, 'fluffy', '2000-10-07', 5730180200.12, timestamp ' { $ now } ' ),
67+ ('Lucy', 3.12, 'shorthair', '2018-06-29', 5780000, timestamp ' { $ now } ' ),
68+ ('Chloe', 2.12, 'spotted', '2013-05-01', 13666200, timestamp ' { $ now } ' ),
69+ ('Misty', 1.96, 'shorthair', '2014-11-24', 12000000, timestamp ' { $ now } ' ),
70+ ('Sam', 3.45, 'fluffy', '2018-12-19', 580.4, timestamp ' { $ now } ' ),
71+ ('Gizmo', 4.65, 'fluffy', '2016-05-11', 120300, timestamp ' { $ now } ' ),
72+ ('Kimba', 1.23, 'spotted', '2020-01-08', 890000, timestamp ' { $ now } ' );
6973
7074 update
7175 "cats"
@@ -93,9 +97,11 @@ public function Run(array $args) {
9397 round(avg("weight_kg"), 2) as "weight_mean"
9498 from
9599 "cats"
100+ where
101+ "created" <= ?
96102 group by
97103 "category"
98- ' );
104+ ', [ new DateTime ()] );
99105
100106 echo "Columns: \n\n" ;
101107
0 commit comments