fix(api): /contracts/recent ORDER BY shadowed by text-cast alias#43
Merged
github-actions[bot] merged 1 commit intomainfrom May 8, 2026
Merged
Conversation
SELECT first_seen_block::text creates an output column with the same
name as the base column but type text. Postgres' ORDER BY resolves
unqualified names to the SELECT-list output FIRST, so the rows came
back sorted by text-lex ("881639" > "2575000") instead of bigint.
Symptom: rank 1 = 0xc9d7a61d (block 881639) ahead of rank 2 = 0x21a24d63
(block 2575000), even though the SQL says DESC. This bit
ethereum-lists/chains#8266 — Marco's contract showed at rank 2 with a
canonical SentrixSafe deploy at rank 1 due to lex ordering.
Fix: qualify ORDER BY ${addresses}.first_seen_block so the planner
references the base column, not the text-cast alias. /whale/tx and
others already do this via `t.value` style table prefixes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
SELECT first_seen_block::textcreates an output column same-named as the base column but typedtext. Postgres'ORDER BYresolves unqualified names to the SELECT-list output first, so rows came back sorted by text-lex ("881639" > "2575000") instead of bigint.Public symptom: ethereum-lists/chains#8266 retest landed with rank 1 = our own canonical SentrixSafe (block 881639) and the contributor's contract (block 2,575,000) at rank 2.
Fix
Qualify
ORDER BY ${addresses}.first_seen_blockso the planner uses the base column, not the text-cast alias. Pattern matches/whale/tx(ORDER BY t.value) and other table-prefixed sorts in this file.Verified
tsc --noEmitclean.