Skip to content

Commit 85a8269

Browse files
committed
fix: table join using quoted ident in all db
1 parent b098e23 commit 85a8269

20 files changed

+40
-27
lines changed

pegjs/athena.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ table_ref
11901190

11911191

11921192
table_join
1193-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
1193+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
11941194
t.join = op;
11951195
t.using = createList(head, tail);
11961196
return t;

pegjs/bigquery.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ table_ref
18641864

18651865

18661866
table_join
1867-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
1867+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
18681868
t.join = op;
18691869
t.using = createList(head, tail);
18701870
return t;

pegjs/db2.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ table_ref
11961196

11971197

11981198
table_join
1199-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
1199+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
12001200
t.join = op;
12011201
t.using = createList(head, tail);
12021202
return t;

pegjs/flinksql.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ table_ref
18511851

18521852

18531853
table_join
1854-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
1854+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
18551855
// => table_base & {join: join_op; using: ident_name[]; }
18561856
t.join = op;
18571857
t.using = createList(head, tail);

pegjs/hive.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ table_ref
11521152

11531153

11541154
table_join
1155-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
1155+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
11561156
t.join = op;
11571157
t.using = createList(head, tail);
11581158
return t;

pegjs/mariadb.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,7 @@ table_ref
21622162

21632163

21642164
table_join
2165-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
2165+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
21662166
t.join = op;
21672167
t.using = createList(head, tail);
21682168
return t;

pegjs/mysql.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ table_ref
24262426

24272427

24282428
table_join
2429-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
2429+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
24302430
t.join = op;
24312431
t.using = createList(head, tail);
24322432
return t;

pegjs/noql.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,7 @@ table_ref
29952995
/ __ t:table_join { /* => table_join */ return t; }
29962996

29972997
table_join
2998-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw tail:(__ COMMA __ ident_name)* __ RPAREN {
2998+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
29992999
// => table_base & {join: join_op; using: ident_name[]; }
30003000
t.join = op;
30013001
t.using = createList(head, tail);

pegjs/postgresql.pegjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,8 +3553,8 @@ table_ref
35533553
/ __ t:table_join { /* => table_join */ return t; }
35543554

35553555
table_join
3556-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw tail:(__ COMMA __ ident_name)* __ RPAREN {
3557-
// => table_base & {join: join_op; using: ident_name[]; }
3556+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
3557+
// => table_base & {join: join_op; using: ident_without_kw_type[]; }
35583558
t.join = op;
35593559
t.using = createList(head, tail);
35603560
return t;

pegjs/redshift.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@ table_ref
30213021
/ __ t:table_join { /* => table_join */ return t; }
30223022

30233023
table_join
3024-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw tail:(__ COMMA __ ident_name)* __ RPAREN {
3024+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
30253025
// => table_base & {join: join_op; using: ident_name[]; }
30263026
t.join = op;
30273027
t.using = createList(head, tail);

pegjs/snowflake.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ table_ref
24012401
/ __ t:table_join { /* => table_join */ return t; }
24022402

24032403
table_join
2404-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
2404+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
24052405
// => table_base & {join: join_op; using: ident_name[]; }
24062406
t.join = op;
24072407
t.using = createList(head, tail);

pegjs/sqlite.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ table_ref
15671567

15681568

15691569
table_join
1570-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
1570+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
15711571
t.join = op;
15721572
t.using = createList(head, tail);
15731573
return t;

pegjs/trino.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ table_ref
23822382
/ __ t:table_join { /* => table_join */ return t; }
23832383

23842384
table_join
2385-
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
2385+
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_without_kw_type tail:(__ COMMA __ ident_without_kw_type)* __ RPAREN {
23862386
// => table_base & {join: join_op; using: ident_name[]; }
23872387
t.join = op;
23882388
t.using = createList(head, tail);

src/tables.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function tablesToSQL(tables) {
187187
str.push(join ? ` ${toUpper(join)}` : ',')
188188
str.push(tableToSQL(joinExpr))
189189
str.push(commonOptionConnector('ON', exprToSQL, on))
190-
if (using) str.push(`USING (${using.map(identifierToSql).join(', ')})`)
190+
if (using) str.push(`USING (${using.map(literalToSQL).join(', ')})`)
191191
clauses.push(str.filter(hasVal).join(' '))
192192
}
193193
return clauses.filter(hasVal).join('')

test/ast.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,12 @@ describe('AST', () => {
438438

439439
it('should support USING keyword (single column)', () => {
440440
expect(getParsedSql('SELECT * FROM t1 JOIN t2 USING (id)'))
441-
.to.equal('SELECT * FROM `t1` INNER JOIN `t2` USING (`id`)');
441+
.to.equal('SELECT * FROM `t1` INNER JOIN `t2` USING (id)');
442442
});
443443

444444
it('should support USING keyword (multiple columns)', () => {
445445
expect(getParsedSql('SELECT * FROM t1 JOIN t2 USING (id1, id2)'))
446-
.to.equal('SELECT * FROM `t1` INNER JOIN `t2` USING (`id1`, `id2`)');
446+
.to.equal('SELECT * FROM `t1` INNER JOIN `t2` USING (id1, id2)');
447447
});
448448
});
449449

test/mysql-mariadb.spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,20 @@ describe('mysql', () => {
12211221
`SELECT "asd
12221222
"`
12231223
]
1224-
}
1224+
},
1225+
{
1226+
title: 'join using quoted ident',
1227+
sql: [
1228+
`SELECT * FROM employees
1229+
inner join salaries using (emp_no)
1230+
order by emp_no desc;
1231+
1232+
SELECT * FROM \`employees\`
1233+
INNER JOIN \`salaries\` USING (\`emp_no\`)
1234+
ORDER BY \`emp_no\` DESC;`,
1235+
'SELECT * FROM `employees` INNER JOIN `salaries` USING (emp_no) ORDER BY `emp_no` DESC ; SELECT * FROM `employees` INNER JOIN `salaries` USING (`emp_no`) ORDER BY `emp_no` DESC'
1236+
]
1237+
},
12251238
]
12261239
SQL_LIST.forEach(sqlInfo => {
12271240
const { title, sql } = sqlInfo

test/postgres.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('Postgres', () => {
5858
`SELECT FirstName
5959
FROM Roster INNER JOIN PlayerStats
6060
USING (LastName);`,
61-
'SELECT FirstName FROM "Roster" INNER JOIN "PlayerStats" USING ("LastName")'
61+
'SELECT FirstName FROM "Roster" INNER JOIN "PlayerStats" USING (LastName)'
6262
]
6363
},
6464
{
@@ -1227,7 +1227,7 @@ describe('Postgres', () => {
12271227
END IF;
12281228
END
12291229
$$;`,
1230-
'CREATE FUNCTION "public".inventory_in_stock(p_inventory_id INTEGER) RETURNS BOOLEAN LANGUAGE plpgsql AS $$ DECLARE v_rentals INTEGER; v_out INTEGER BEGIN SELECT COUNT(*) INTO "v_rentals" FROM "rental" WHERE inventory_id = p_inventory_id ; IF v_rentals = 0 THEN RETURN TRUE; END IF ; SELECT COUNT(rental_id) INTO "v_out" FROM "inventory" LEFT JOIN "rental" USING ("inventory_id") WHERE "inventory".inventory_id = p_inventory_id AND "rental".return_date IS NULL ; IF v_out > 0 THEN RETURN FALSE; ELSEIF v_out = 0 THEN RETURN FALSE ; ELSE RETURN TRUE; END IF END $$'
1230+
'CREATE FUNCTION "public".inventory_in_stock(p_inventory_id INTEGER) RETURNS BOOLEAN LANGUAGE plpgsql AS $$ DECLARE v_rentals INTEGER; v_out INTEGER BEGIN SELECT COUNT(*) INTO "v_rentals" FROM "rental" WHERE inventory_id = p_inventory_id ; IF v_rentals = 0 THEN RETURN TRUE; END IF ; SELECT COUNT(rental_id) INTO "v_out" FROM "inventory" LEFT JOIN "rental" USING (inventory_id) WHERE "inventory".inventory_id = p_inventory_id AND "rental".return_date IS NULL ; IF v_out > 0 THEN RETURN FALSE; ELSEIF v_out = 0 THEN RETURN FALSE ; ELSE RETURN TRUE; END IF END $$'
12311231
]
12321232
},
12331233
{
@@ -1511,10 +1511,10 @@ describe('Postgres', () => {
15111511
FROM
15121512
film f
15131513
INNER JOIN film_actor fa USING (film_id)
1514-
INNER JOIN actor a USING (actor_id)
1514+
INNER JOIN actor a USING ("actor_id")
15151515
GROUP BY
15161516
f.title;`,
1517-
`SELECT "f".title, STRING_AGG("a".first_name || ' ' || "a".last_name, ',' ORDER BY "a".first_name ASC, "a".last_name ASC) AS "actors" FROM "film" AS "f" INNER JOIN "film_actor" AS "fa" USING ("film_id") INNER JOIN "actor" AS "a" USING ("actor_id") GROUP BY "f".title`
1517+
`SELECT "f".title, STRING_AGG("a".first_name || ' ' || "a".last_name, ',' ORDER BY "a".first_name ASC, "a".last_name ASC) AS "actors" FROM "film" AS "f" INNER JOIN "film_actor" AS "fa" USING (film_id) INNER JOIN "actor" AS "a" USING ("actor_id") GROUP BY "f".title`
15181518
]
15191519
},
15201520
{

test/redshift.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('redshift', () => {
2929
left join ppc_keywords_mapping mp using (campaign_keyword)
3030
)
3131
select is_brand as "b/nb" from pv where mp."brand/non-brand" = 'brand'`
32-
expect(getParsedSql(sql)).to.be.equal(`WITH "pv" AS (SELECT action_date, visitor_id_v, visit_country_name, referer_channel_group, email, sgid, "mp"."brand/non-brand" AS "is_brand" FROM "dwh_fact_pageviews" AS "pv" LEFT JOIN "ppc_keywords_mapping" AS "mp" USING ("campaign_keyword")) SELECT is_brand AS "b/nb" FROM "pv" WHERE "mp"."brand/non-brand" = 'brand'`)
32+
expect(getParsedSql(sql)).to.be.equal(`WITH "pv" AS (SELECT action_date, visitor_id_v, visit_country_name, referer_channel_group, email, sgid, "mp"."brand/non-brand" AS "is_brand" FROM "dwh_fact_pageviews" AS "pv" LEFT JOIN "ppc_keywords_mapping" AS "mp" USING (campaign_keyword)) SELECT is_brand AS "b/nb" FROM "pv" WHERE "mp"."brand/non-brand" = 'brand'`)
3333
})
3434

3535
it('should support unary operator', () => {

test/select.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,16 @@ describe('select', () => {
540540

541541
expect(ast.from).to.eql([
542542
{ db: null, table: 't1', as: null },
543-
{ db: null, table: 't2', as: null, join: 'INNER JOIN', using: ['id'] }
543+
{ db: null, table: 't2', as: null, join: 'INNER JOIN', using: [{ type: 'default', value: 'id' }] }
544544
]);
545545
});
546546

547547
it('should parse joins with USING (multiple columns)', () => {
548-
const ast = parser.astify('SELECT * FROM t1 JOIN t2 USING (id1, id2)');
548+
const ast = parser.astify('SELECT * FROM t1 JOIN t2 USING (id1, `id2`)');
549549

550550
expect(ast.from).to.eql([
551551
{ db: null, table: 't1', as: null },
552-
{ db: null, table: 't2', as: null, join: 'INNER JOIN', using: ['id1', 'id2'] }
552+
{ db: null, table: 't2', as: null, join: 'INNER JOIN', using: [{ type: 'default', value: 'id1' }, { type: 'backticks_quote_string', value: 'id2' }] }
553553
]);
554554
});
555555
});

test/snowflake.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ describe('snowflake', () => {
373373
using(date)
374374
group by all)
375375
unpivot(transaction_amount_usd FOR transaction_type IN (Charge, Taxes_and_Fees)))))`,
376-
`SELECT "transaction_date", "platform", "date_granularity", "transaction_type", "buyer_country", "sku", "transaction_currency", "exchange_rate", "transaction_amount_usd", "transaction_amount_local_currency", "transaction_amount_ils" FROM ((SELECT 'android' AS "platform", 'Daily' AS "date_granularity", "transaction_date", "transaction_type", "buyer_country", "sku", "transaction_currency", "exchange_rate", SUM("transaction_amount_usd") AS "transaction_amount_usd", SUM("transaction_amount_local_currency") AS "transaction_amount_local_currency", SUM("amount_merchant_currency") AS "transaction_amount_ils" FROM (SELECT to_date("ge"."transaction_date", 'Mon DD, YYYY') AS "transaction_date", "ge"."transaction_type" AS "transaction_type", "ge"."product_title" AS "product", "ge"."sku_id" AS "sku", "ge"."buyer_country" AS "buyer_country", "ge"."buyer_currency" AS "transaction_currency", "er"."rate" AS "exchange_rate", "ge"."amount_buyer_currency" AS "transaction_amount_local_currency", "ge"."amount_buyer_currency" / "er"."rate" AS "transaction_amount_usd", "ge"."amount_merchant_currency" AS "amount_merchant_currency" FROM (SELECT DISTINCT * FROM "staging"."raw"."google_play_store_earnings") AS "ge" INNER JOIN "F_EXCHANGE_RATES" AS "er" ON date("er"."time") = to_date("ge"."transaction_date", 'Mon DD, YYYY') AND "er"."currency" = "ge"."buyer_currency") GROUP BY ALL) UNION ALL (SELECT "platform", "date_granularity", "transaction_date", "transaction_type", "buyer_country", "sku", "transaction_currency", "exchange_rate", "transaction_amount_usd", CASE WHEN "transaction_type" = 'CHARGE' THEN "transaction_amount_local_currency" WHEN "transaction_type" = 'TAXES_AND_FEES' THEN "Taxes_and_Fees_local_currency" END AS "transaction_amount_local_currency", "transaction_amount_usd" * "ils_exchange_rate" AS "transaction_amount_ils" FROM (SELECT DISTINCT * FROM (SELECT 'ios' AS "platform", "date_granularity", "date" AS "transaction_date", "buyer_country", "sku", "transaction_currency", "exchange_rate", "ils"."exchange_rate" AS "ils_exchange_rate", SUM("transaction_amount_usd") AS "Charge", SUM("developer_proceeds_usd") AS "Taxes_and_Fees", SUM("transaction_amount_local_currency") AS "transaction_amount_local_currency", SUM("developer_proceeds") AS "Taxes_and_Fees_local_currency" FROM (SELECT date("ge1"."begin_date") AS "date", "ge1"."date_granularity" AS "date_granularity", "ge1"."title" AS "sku", "ge1"."country_code" AS "buyer_country", "ge1"."currency_of_proceeds" AS "transaction_currency", "er1"."rate" AS "exchange_rate", "ge1"."units" AS "units", ("ge1"."customer_price-ge1"."developer_proceeds") * "ge1"."units" * (-1) AS "developer_proceeds", "ge1"."customer_price" * "ge1"."units" AS "transaction_amount_local_currency", "ge1"."customer_price" * "ge1"."units" / "er1"."rate" AS "transaction_amount_usd", ("ge1"."customer_price-ge1"."developer_proceeds") * "ge1"."units" / "er1"."rate" * (-1) AS "developer_proceeds_usd" FROM (SELECT DISTINCT * FROM "staging"."raw"."apps_store_connect_sales") AS "ge1" INNER JOIN (SELECT DISTINCT * FROM "F_EXCHANGE_RATES") AS "er1" ON date("er1"."time") = date("ge1"."begin_date") AND "er1"."currency" = "ge1"."currency_of_proceeds") LEFT JOIN (SELECT date("time") AS "date", "currency", "rate" AS "exchange_rate" FROM (SELECT DISTINCT * FROM "F_EXCHANGE_RATES") WHERE "currency" = 'ILS') AS "ils" USING ("date") GROUP BY ALL) UNPIVOT("transaction_amount_usd" FOR "transaction_type" IN ("Charge", "Taxes_and_Fees")))))`,
376+
`SELECT "transaction_date", "platform", "date_granularity", "transaction_type", "buyer_country", "sku", "transaction_currency", "exchange_rate", "transaction_amount_usd", "transaction_amount_local_currency", "transaction_amount_ils" FROM ((SELECT 'android' AS "platform", 'Daily' AS "date_granularity", "transaction_date", "transaction_type", "buyer_country", "sku", "transaction_currency", "exchange_rate", SUM("transaction_amount_usd") AS "transaction_amount_usd", SUM("transaction_amount_local_currency") AS "transaction_amount_local_currency", SUM("amount_merchant_currency") AS "transaction_amount_ils" FROM (SELECT to_date("ge"."transaction_date", 'Mon DD, YYYY') AS "transaction_date", "ge"."transaction_type" AS "transaction_type", "ge"."product_title" AS "product", "ge"."sku_id" AS "sku", "ge"."buyer_country" AS "buyer_country", "ge"."buyer_currency" AS "transaction_currency", "er"."rate" AS "exchange_rate", "ge"."amount_buyer_currency" AS "transaction_amount_local_currency", "ge"."amount_buyer_currency" / "er"."rate" AS "transaction_amount_usd", "ge"."amount_merchant_currency" AS "amount_merchant_currency" FROM (SELECT DISTINCT * FROM "staging"."raw"."google_play_store_earnings") AS "ge" INNER JOIN "F_EXCHANGE_RATES" AS "er" ON date("er"."time") = to_date("ge"."transaction_date", 'Mon DD, YYYY') AND "er"."currency" = "ge"."buyer_currency") GROUP BY ALL) UNION ALL (SELECT "platform", "date_granularity", "transaction_date", "transaction_type", "buyer_country", "sku", "transaction_currency", "exchange_rate", "transaction_amount_usd", CASE WHEN "transaction_type" = 'CHARGE' THEN "transaction_amount_local_currency" WHEN "transaction_type" = 'TAXES_AND_FEES' THEN "Taxes_and_Fees_local_currency" END AS "transaction_amount_local_currency", "transaction_amount_usd" * "ils_exchange_rate" AS "transaction_amount_ils" FROM (SELECT DISTINCT * FROM (SELECT 'ios' AS "platform", "date_granularity", "date" AS "transaction_date", "buyer_country", "sku", "transaction_currency", "exchange_rate", "ils"."exchange_rate" AS "ils_exchange_rate", SUM("transaction_amount_usd") AS "Charge", SUM("developer_proceeds_usd") AS "Taxes_and_Fees", SUM("transaction_amount_local_currency") AS "transaction_amount_local_currency", SUM("developer_proceeds") AS "Taxes_and_Fees_local_currency" FROM (SELECT date("ge1"."begin_date") AS "date", "ge1"."date_granularity" AS "date_granularity", "ge1"."title" AS "sku", "ge1"."country_code" AS "buyer_country", "ge1"."currency_of_proceeds" AS "transaction_currency", "er1"."rate" AS "exchange_rate", "ge1"."units" AS "units", ("ge1"."customer_price-ge1"."developer_proceeds") * "ge1"."units" * (-1) AS "developer_proceeds", "ge1"."customer_price" * "ge1"."units" AS "transaction_amount_local_currency", "ge1"."customer_price" * "ge1"."units" / "er1"."rate" AS "transaction_amount_usd", ("ge1"."customer_price-ge1"."developer_proceeds") * "ge1"."units" / "er1"."rate" * (-1) AS "developer_proceeds_usd" FROM (SELECT DISTINCT * FROM "staging"."raw"."apps_store_connect_sales") AS "ge1" INNER JOIN (SELECT DISTINCT * FROM "F_EXCHANGE_RATES") AS "er1" ON date("er1"."time") = date("ge1"."begin_date") AND "er1"."currency" = "ge1"."currency_of_proceeds") LEFT JOIN (SELECT date("time") AS "date", "currency", "rate" AS "exchange_rate" FROM (SELECT DISTINCT * FROM "F_EXCHANGE_RATES") WHERE "currency" = 'ILS') AS "ils" USING (date) GROUP BY ALL) UNPIVOT("transaction_amount_usd" FOR "transaction_type" IN ("Charge", "Taxes_and_Fees")))))`,
377377
]
378378
},
379379
{

0 commit comments

Comments
 (0)