patch: prevent multiple rows from inner query

` UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address`
This commit is contained in:
Mohamed Sohail 2022-11-16 17:01:44 +03:00 committed by GitHub
parent e158ce28bc
commit f93727925e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,8 +20,8 @@ SELECT phone_number FROM users WHERE blockchain_address = $1;
-- name: account-latest-transactions -- name: account-latest-transactions
-- Returns the first page of a users latest transactions -- Returns the first page of a users latest transactions
SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN tokens ON transactions.token_address = tokens.token_address INNER JOIN tokens ON transactions.token_address = tokens.token_address
@ -30,8 +30,8 @@ WHERE users.phone_number = $1 ORDER BY transactions.id DESC LIMIT $2;
-- name: account-latest-transactions-next -- name: account-latest-transactions-next
-- Returns the next page based on a cursor -- Returns the next page based on a cursor
SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN tokens ON transactions.token_address = tokens.token_address INNER JOIN tokens ON transactions.token_address = tokens.token_address
@ -41,8 +41,8 @@ WHERE users.phone_number = $1 AND transactions.id < $2 ORDER BY transactions.id
-- Returns the previous page based on cursor -- Returns the previous page based on cursor
SELECT * FROM ( SELECT * FROM (
SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN tokens ON transactions.token_address = tokens.token_address INNER JOIN tokens ON transactions.token_address = tokens.token_address
@ -52,8 +52,8 @@ SELECT * FROM (
-- name: account-latest-transactions-by-token -- name: account-latest-transactions-by-token
-- Returns the first page of a users latest transactions, filter by token -- Returns the first page of a users latest transactions, filter by token
SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN tokens ON transactions.token_address = tokens.token_address INNER JOIN tokens ON transactions.token_address = tokens.token_address
@ -62,8 +62,8 @@ WHERE users.phone_number = $1 AND tokens.token_symbol = $2 ORDER BY transactions
-- name: account-latest-transactions-by-token-next -- name: account-latest-transactions-by-token-next
-- Returns the next page based on a cursor, filter by token -- Returns the next page based on a cursor, filter by token
SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN tokens ON transactions.token_address = tokens.token_address INNER JOIN tokens ON transactions.token_address = tokens.token_address
@ -73,8 +73,8 @@ WHERE users.phone_number = $1 AND tokens.token_symbol = $2 AND transactions.id <
-- Returns the previous page based on cursor, filter by token -- Returns the previous page based on cursor, filter by token
SELECT * FROM ( SELECT * FROM (
SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN tokens ON transactions.token_address = tokens.token_address INNER JOIN tokens ON transactions.token_address = tokens.token_address
@ -84,8 +84,8 @@ SELECT * FROM (
-- name: account-latest-transactions-by-archived-token -- name: account-latest-transactions-by-archived-token
-- Returns the first page of a users latest transactions, filter by token -- Returns the first page of a users latest transactions, filter by token
SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_addres) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address
@ -94,8 +94,8 @@ WHERE users.phone_number = $1 AND archived_tokens.token_address = $2 ORDER BY tr
-- name: account-latest-transactions-by-archived-token-next -- name: account-latest-transactions-by-archived-token-next
-- Returns the next page based on a cursor, filter by token -- Returns the next page based on a cursor, filter by token
SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address
@ -105,8 +105,8 @@ WHERE users.phone_number = $1 AND archived_tokens.token_address = $2 AND transac
-- Returns the previous page based on cursor, filter by token -- Returns the previous page based on cursor, filter by token
SELECT * FROM ( SELECT * FROM (
SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success, SELECT transactions.id, transactions.date_block, transactions.tx_hash, archived_tokens.token_symbol, transactions.sender_address, transactions.recipient_address, transactions.tx_value, transactions.success,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.sender_address) as sender_identifier, (SELECT phone_number FROM users WHERE blockchain_address = transactions.sender_address) as sender_identifier,
(SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address UNION ALL SELECT address_description FROM sys_accounts WHERE sys_address = transactions.recipient_address) as recipient_identifier (SELECT phone_number FROM users WHERE blockchain_address = transactions.recipient_address) as recipient_identifier
FROM transactions FROM transactions
INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address)) INNER JOIN users ON ((transactions.sender_address = users.blockchain_address) OR (transactions.recipient_address = users.blockchain_address))
INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address INNER JOIN archived_tokens ON transactions.token_address = archived_tokens.token_address