Skip to content

Commit 0696ebb

Browse files
authored
Auto-format .sql files using github.com/sql-formatter-org/sql-formatter - twelve-days (#185)
1 parent c47f1d3 commit 0696ebb

File tree

4 files changed

+248
-95
lines changed

4 files changed

+248
-95
lines changed
Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,67 @@
11
DROP TABLE IF EXISTS inputs;
2+
23
CREATE TEMPORARY TABLE inputs (
3-
idx INTEGER NOT NULL,
4-
ordinal TEXT NOT NULL,
5-
item TEXT NOT NULL
4+
idx INTEGER NOT NULL,
5+
ordinal TEXT NOT NULL,
6+
item TEXT NOT NULL
67
);
7-
INSERT INTO inputs (idx, ordinal, item)
8+
9+
INSERT INTO
10+
inputs (idx, ordinal, item)
811
VALUES
9-
( 1, 'first', 'a Partridge in a Pear Tree'),
10-
( 2, 'second', 'two Turtle Doves' ),
11-
( 3, 'third', 'three French Hens' ),
12-
( 4, 'fourth', 'four Calling Birds' ),
13-
( 5, 'fifth', 'five Gold Rings' ),
14-
( 6, 'sixth', 'six Geese-a-Laying' ),
15-
( 7, 'seventh', 'seven Swans-a-Swimming' ),
16-
( 8, 'eighth', 'eight Maids-a-Milking' ),
17-
( 9, 'ninth', 'nine Ladies Dancing' ),
18-
(10, 'tenth', 'ten Lords-a-Leaping' ),
19-
(11, 'eleventh', 'eleven Pipers Piping' ),
20-
(12, 'twelfth', 'twelve Drummers Drumming' );
12+
(1, 'first', 'a Partridge in a Pear Tree'),
13+
(2, 'second', 'two Turtle Doves'),
14+
(3, 'third', 'three French Hens'),
15+
(4, 'fourth', 'four Calling Birds'),
16+
(5, 'fifth', 'five Gold Rings'),
17+
(6, 'sixth', 'six Geese-a-Laying'),
18+
(7, 'seventh', 'seven Swans-a-Swimming'),
19+
(8, 'eighth', 'eight Maids-a-Milking'),
20+
(9, 'ninth', 'nine Ladies Dancing'),
21+
(10, 'tenth', 'ten Lords-a-Leaping'),
22+
(11, 'eleventh', 'eleven Pipers Piping'),
23+
(12, 'twelfth', 'twelve Drummers Drumming');
2124

2225
DROP TABLE IF EXISTS verses;
26+
2327
CREATE TEMPORARY TABLE verses AS
24-
SELECT idx,
25-
PRINTF(
26-
'On the %s day of Christmas my true love gave to me: %s.',
27-
ordinal,
28-
items
29-
) AS verse
30-
FROM (
28+
SELECT
29+
idx,
30+
PRINTF(
31+
'On the %s day of Christmas my true love gave to me: %s.',
32+
ordinal,
33+
items
34+
) AS verse
35+
FROM
36+
(
3137
SELECT
32-
idx, ordinal,
33-
GROUP_CONCAT(item, IIF(idx = 1, ', and ', ', '))
34-
OVER(
35-
ORDER BY idx DESC ROWS BETWEEN 0 PRECEDING AND 12 FOLLOWING
36-
) items
37-
FROM inputs
38-
ORDER BY idx
39-
)
40-
;
38+
idx,
39+
ordinal,
40+
GROUP_CONCAT(item, IIF(idx = 1, ', and ', ', ')) OVER (
41+
ORDER BY
42+
idx DESC ROWS BETWEEN 0 PRECEDING
43+
AND 12 FOLLOWING
44+
) items
45+
FROM
46+
inputs
47+
ORDER BY
48+
idx
49+
);
4150

4251
UPDATE "twelve-days"
43-
SET result = (
44-
SELECT GROUP_CONCAT(verse, CHAR(10))
45-
FROM (
46-
SELECT verse
47-
FROM verses
48-
WHERE idx BETWEEN start_verse AND end_verse
49-
ORDER BY idx
50-
)
51-
)
52-
;
52+
SET
53+
result = (
54+
SELECT
55+
GROUP_CONCAT(verse, CHAR(10))
56+
FROM
57+
(
58+
SELECT
59+
verse
60+
FROM
61+
verses
62+
WHERE
63+
idx BETWEEN start_verse AND end_verse
64+
ORDER BY
65+
idx
66+
)
67+
);

exercises/practice/twelve-days/create_fixture.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
DROP TABLE IF EXISTS "twelve-days";
2+
23
CREATE TABLE "twelve-days" (
3-
start_verse INTEGER NOT NULL,
4-
end_verse INTEGER NOT NULL,
5-
result TEXT
4+
start_verse INTEGER NOT NULL,
5+
end_verse INTEGER NOT NULL,
6+
result TEXT
67
);
78

89
.mode csv
Lines changed: 131 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,136 @@
11
DROP TABLE IF EXISTS tests;
2+
23
CREATE TABLE IF NOT EXISTS tests (
3-
-- uuid and description are taken from the test.toml file
4-
uuid TEXT PRIMARY KEY,
5-
description TEXT NOT NULL,
6-
-- The following section is needed by the online test-runner
7-
status TEXT DEFAULT 'fail',
8-
message TEXT,
9-
output TEXT,
10-
test_code TEXT,
11-
task_id INTEGER DEFAULT NULL,
12-
-- Here are columns for the actual tests
13-
start_verse INTEGER NOT NULL,
14-
end_verse INTEGER NOT NULL,
15-
expected TEXT NOT NULL
4+
-- uuid and description are taken from the test.toml file
5+
uuid TEXT PRIMARY KEY,
6+
description TEXT NOT NULL,
7+
-- The following section is needed by the online test-runner
8+
status TEXT DEFAULT 'fail',
9+
message TEXT,
10+
output TEXT,
11+
test_code TEXT,
12+
task_id INTEGER DEFAULT NULL,
13+
-- Here are columns for the actual tests
14+
start_verse INTEGER NOT NULL,
15+
end_verse INTEGER NOT NULL,
16+
expected TEXT NOT NULL
1617
);
1718

18-
INSERT INTO tests (uuid, description, start_verse, end_verse, expected)
19-
VALUES
20-
('c0b5a5e6-c89d-49b1-a6b2-9f523bff33f7', 'first day a partridge in a pear tree', 1, 1, 'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.'),
21-
('1c64508a-df3d-420a-b8e1-fe408847854a', 'second day two turtle doves', 2, 2, 'On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.'),
22-
('a919e09c-75b2-4e64-bb23-de4a692060a8', 'third day three french hens', 3, 3, 'On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
23-
('9bed8631-ec60-4894-a3bb-4f0ec9fbe68d', 'fourth day four calling birds', 4, 4, 'On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
24-
('cf1024f0-73b6-4545-be57-e9cea565289a', 'fifth day five gold rings', 5, 5, 'On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
25-
('50bd3393-868a-4f24-a618-68df3d02ff04', 'sixth day six geese-a-laying', 6, 6, 'On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
26-
('8f29638c-9bf1-4680-94be-e8b84e4ade83', 'seventh day seven swans-a-swimming', 7, 7, 'On the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
27-
('7038d6e1-e377-47ad-8c37-10670a05bc05', 'eighth day eight maids-a-milking', 8, 8, 'On the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
28-
('37a800a6-7a56-4352-8d72-0f51eb37cfe8', 'ninth day nine ladies dancing', 9, 9, 'On the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
29-
('10b158aa-49ff-4b2d-afc3-13af9133510d', 'tenth day ten lords-a-leaping', 10, 10, 'On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
30-
('08d7d453-f2ba-478d-8df0-d39ea6a4f457', 'eleventh day eleven pipers piping', 11, 11, 'On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
31-
('0620fea7-1704-4e48-b557-c05bf43967f0', 'twelfth day twelve drummers drumming', 12, 12, 'On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
32-
('da8b9013-b1e8-49df-b6ef-ddec0219e398', 'recites first three verses of the song', 1, 3, 'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\nOn the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\nOn the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
33-
('c095af0d-3137-4653-ad32-bfb899eda24c', 'recites three verses from the middle of the song', 4, 6, 'On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
34-
('20921bc9-cc52-4627-80b3-198cbbfcf9b7', 'recites the whole song', 1, 12, 'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\nOn the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\nOn the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.');
19+
INSERT INTO
20+
tests (
21+
uuid,
22+
description,
23+
start_verse,
24+
end_verse,
25+
expected
26+
)
27+
VALUES
28+
(
29+
'c0b5a5e6-c89d-49b1-a6b2-9f523bff33f7',
30+
'first day a partridge in a pear tree',
31+
1,
32+
1,
33+
'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.'
34+
),
35+
(
36+
'1c64508a-df3d-420a-b8e1-fe408847854a',
37+
'second day two turtle doves',
38+
2,
39+
2,
40+
'On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.'
41+
),
42+
(
43+
'a919e09c-75b2-4e64-bb23-de4a692060a8',
44+
'third day three french hens',
45+
3,
46+
3,
47+
'On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
48+
),
49+
(
50+
'9bed8631-ec60-4894-a3bb-4f0ec9fbe68d',
51+
'fourth day four calling birds',
52+
4,
53+
4,
54+
'On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
55+
),
56+
(
57+
'cf1024f0-73b6-4545-be57-e9cea565289a',
58+
'fifth day five gold rings',
59+
5,
60+
5,
61+
'On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
62+
),
63+
(
64+
'50bd3393-868a-4f24-a618-68df3d02ff04',
65+
'sixth day six geese-a-laying',
66+
6,
67+
6,
68+
'On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
69+
),
70+
(
71+
'8f29638c-9bf1-4680-94be-e8b84e4ade83',
72+
'seventh day seven swans-a-swimming',
73+
7,
74+
7,
75+
'On the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
76+
),
77+
(
78+
'7038d6e1-e377-47ad-8c37-10670a05bc05',
79+
'eighth day eight maids-a-milking',
80+
8,
81+
8,
82+
'On the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
83+
),
84+
(
85+
'37a800a6-7a56-4352-8d72-0f51eb37cfe8',
86+
'ninth day nine ladies dancing',
87+
9,
88+
9,
89+
'On the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
90+
),
91+
(
92+
'10b158aa-49ff-4b2d-afc3-13af9133510d',
93+
'tenth day ten lords-a-leaping',
94+
10,
95+
10,
96+
'On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
97+
),
98+
(
99+
'08d7d453-f2ba-478d-8df0-d39ea6a4f457',
100+
'eleventh day eleven pipers piping',
101+
11,
102+
11,
103+
'On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
104+
),
105+
(
106+
'0620fea7-1704-4e48-b557-c05bf43967f0',
107+
'twelfth day twelve drummers drumming',
108+
12,
109+
12,
110+
'On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
111+
),
112+
(
113+
'da8b9013-b1e8-49df-b6ef-ddec0219e398',
114+
'recites first three verses of the song',
115+
1,
116+
3,
117+
'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\nOn the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\nOn the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
118+
),
119+
(
120+
'c095af0d-3137-4653-ad32-bfb899eda24c',
121+
'recites three verses from the middle of the song',
122+
4,
123+
6,
124+
'On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
125+
),
126+
(
127+
'20921bc9-cc52-4627-80b3-198cbbfcf9b7',
128+
'recites the whole song',
129+
1,
130+
12,
131+
'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\nOn the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\nOn the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'
132+
);
35133

36-
UPDATE tests SET expected = REPLACE(expected, '\n', CHAR(10));
134+
UPDATE tests
135+
SET
136+
expected = REPLACE(expected, '\n', CHAR(10));

0 commit comments

Comments
 (0)