Skip to content

Commit 6246b1d

Browse files
committed
fix example tester
1 parent 1de4d3d commit 6246b1d

2 files changed

Lines changed: 44 additions & 32 deletions

File tree

examples/formatting_showcase.sql

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- #! ../data/international_sales.csv
12
-- Formatting Functions Showcase
23
-- Quick examples demonstrating RENDER_NUMBER and FORMAT_CURRENCY
34
-- data: data/international_sales.csv
@@ -6,65 +7,74 @@
67

78
-- Standard number formatting with thousand separators
89
SELECT RENDER_NUMBER(1234567.89) as standard_format;
10+
go
911

1012
-- Compact notation (k, M, B, T)
1113
SELECT
12-
RENDER_NUMBER(1500, 'compact') as thousands,
13-
RENDER_NUMBER(1500000, 'compact') as millions,
14-
RENDER_NUMBER(1500000000, 'compact') as billions;
14+
RENDER_NUMBER(1500, 'compact') AS thousands,
15+
RENDER_NUMBER(1500000, 'compact') AS millions,
16+
RENDER_NUMBER(1500000000, 'compact') AS billions;
17+
go
1518

1619
-- Regional number formats
1720
SELECT
18-
RENDER_NUMBER(1234.56, 'us') as us_format, -- 1,234.56
19-
RENDER_NUMBER(1234.56, 'eu') as eu_format, -- 1.234,56
20-
RENDER_NUMBER(1234.56, 'ch') as swiss_format, -- 1'234.56
21-
RENDER_NUMBER(1234.56, 'in') as indian_format; -- 1,234.56
21+
RENDER_NUMBER(1234.56, 'us') AS us_format,
22+
RENDER_NUMBER(1234.56, 'eu') AS eu_format,
23+
RENDER_NUMBER(1234.56, 'ch') AS swiss_format,
24+
RENDER_NUMBER(1234.56, 'in') AS indian_format
25+
go
2226

2327
-- === FORMAT_CURRENCY Examples ===
24-
25-
-- Basic currency formatting with symbols
2628
SELECT
27-
FORMAT_CURRENCY(1234.56, 'USD') as dollars,
28-
FORMAT_CURRENCY(1234.56, 'EUR') as euros,
29-
FORMAT_CURRENCY(1234.56, 'GBP') as pounds,
30-
FORMAT_CURRENCY(50000, 'JPY') as yen;
29+
FORMAT_CURRENCY(1234.56, 'USD') AS dollars,
30+
FORMAT_CURRENCY(1234.56, 'EUR') AS euros,
31+
FORMAT_CURRENCY(1234.56, 'GBP') AS pounds,
32+
FORMAT_CURRENCY(50000, 'JPY') AS yen;
33+
go
3134

3235
-- Compact currency formats
3336
SELECT
34-
FORMAT_CURRENCY(3000, 'GBP', 'compact') as compact_symbol, -- £3k
35-
FORMAT_CURRENCY(3000, 'GBP', 'compact_code') as compact_code, -- 3k GBP
36-
FORMAT_CURRENCY(1500000, 'USD', 'compact') as millions_usd; -- $1.5M
37+
FORMAT_CURRENCY(3000, 'GBP', 'compact') AS compact_symbol,
38+
FORMAT_CURRENCY(3000, 'GBP', 'compact_code') AS compact_code,
39+
FORMAT_CURRENCY(1500000, 'USD', 'compact') AS millions_usd
40+
go
3741

3842
-- === Real Data Examples ===
39-
40-
-- Format prices from actual data using currency column
4143
SELECT
4244
country,
4345
product,
4446
amount,
4547
currency,
46-
FORMAT_CURRENCY(amount, currency) as local_price,
47-
FORMAT_CURRENCY(amount, currency, 'compact_code') as price_code
48+
FORMAT_CURRENCY(amount, currency) AS local_price,
49+
FORMAT_CURRENCY(amount, currency, 'compact_code') AS price_code
4850
FROM international_sales
4951
WHERE region = 'Europe'
5052
LIMIT 5;
53+
go
5154

5255
-- Sales summary with formatted totals
53-
SELECT
54-
region,
55-
COUNT(*) as num_sales,
56-
RENDER_NUMBER(SUM(amount * quantity), 'compact') as total_compact,
57-
RENDER_NUMBER(AVG(amount), 'standard', 2) as avg_price
58-
FROM international_sales
59-
GROUP BY region
60-
ORDER BY SUM(amount * quantity) DESC;
56+
WITH
57+
summed AS (
58+
SELECT
59+
region,
60+
amount * quantity AS notional,
61+
COUNT('*') AS num_sales,
62+
RENDER_NUMBER(SUM(amount * quantity), 'compact') AS total_compact,
63+
RENDER_NUMBER(AVG(amount), 'standard', 2) AS avg_price
64+
FROM international_sales
65+
)
66+
SELECT *
67+
FROM summed
68+
ORDER BY notional DESC;
69+
go
6170

6271
-- Multi-currency report
6372
SELECT
6473
product,
65-
SUM(quantity) as units_sold,
66-
RENDER_NUMBER(SUM(quantity)) as formatted_units,
67-
RENDER_NUMBER(COUNT(DISTINCT currency)) as num_currencies
74+
SUM(quantity) AS units_sold,
75+
RENDER_NUMBER(SUM(quantity)) AS formatted_units,
76+
RENDER_NUMBER(COUNT(DISTINCT currency)) AS num_currencies
6877
FROM international_sales
6978
GROUP BY product
70-
ORDER BY units_sold DESC;
79+
ORDER BY units_sold DESC;
80+
go

scripts/test_all_examples.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ skip_examples["web_cte_file_upload.sql"]=1
4343
skip_examples["fix_message_analysis.sql"]=1
4444
skip_examples["fix_messages_with_selectors.sql"]=1
4545
skip_examples["parameterized_trades.sql"]=1
46+
skip_examples["format.sql"]=1
47+
skip_examples["format_body.sql"]=1
4648

4749
failed=0
4850
passed=0

0 commit comments

Comments
 (0)