Skip to content

Commit

Permalink
Merge pull request #736 from EspressoSystems/jb/multi-column-order-by
Browse files Browse the repository at this point in the history
Fix multi-column ORDER BY clauses
  • Loading branch information
jbearer authored Nov 15, 2024
2 parents b41a630 + 6057ec3 commit 050aae1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/data_source/storage/sql/queries/availability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ where
JOIN payload AS p ON h.height = p.height
JOIN transaction AS t ON t.block_height = h.height
WHERE t.hash = {hash_param}
ORDER BY (t.block_height, t.index) ASC
ORDER BY t.block_height, t.index
LIMIT 1"
);
let row = query.query(&sql).fetch_one(self.as_mut()).await?;
Expand Down
12 changes: 6 additions & 6 deletions src/data_source/storage/sql/queries/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ where
// returned results based on.
let transaction_target_query = match target {
TransactionIdentifier::Latest => query(
"SELECT t.block_height AS height, t.index AS index FROM transaction AS t ORDER BY (t.block_height, t.index) DESC LIMIT 1",
"SELECT t.block_height AS height, t.index AS index FROM transaction AS t ORDER BY t.block_height DESC, t.index DESC LIMIT 1",
),
TransactionIdentifier::HeightAndOffset(height, _) => query(
"SELECT t.block_height AS height, t.index AS index FROM transaction AS t WHERE t.block_height = $1 ORDER BY (t.block_height, t.index) DESC LIMIT 1",
"SELECT t.block_height AS height, t.index AS index FROM transaction AS t WHERE t.block_height = $1 ORDER BY t.block_height DESC, t.index DESC LIMIT 1",
)
.bind(*height as i64),
TransactionIdentifier::Hash(hash) => query(
"SELECT t.block_height AS height, t.index AS index FROM transaction AS t WHERE t.hash = $1 ORDER BY (t.block_height, t.index) DESC LIMIT 1",
"SELECT t.block_height AS height, t.index AS index FROM transaction AS t WHERE t.hash = $1 ORDER BY t.block_height DESC, t.index DESC LIMIT 1",
)
.bind(hash.to_string()),
};
Expand Down Expand Up @@ -264,7 +264,7 @@ where
SELECT t.block_height
FROM transaction AS t
WHERE (t.block_height, t.index) <= ({}, {})
ORDER BY (t.block_height, t.index) DESC
ORDER BY t.block_height DESC, t.index DESC
LIMIT {}
)
ORDER BY h.height DESC",
Expand Down Expand Up @@ -350,7 +350,7 @@ where
SELECT t1.block_height
FROM transaction AS t1
WHERE t1.block_height = {}
ORDER BY (t1.block_height, t1.index)
ORDER BY t1.block_height, t1.index
OFFSET {}
LIMIT 1
)
Expand All @@ -366,7 +366,7 @@ where
SELECT t1.block_height
FROM transaction AS t1
WHERE t1.hash = {}
ORDER BY (t1.block_height, t1.index) DESC
ORDER BY t1.block_height DESC, t1.index DESC
LIMIT 1
)
ORDER BY h.height DESC",
Expand Down

0 comments on commit 050aae1

Please sign in to comment.