Skip to content

fix(api): /contracts/recent ORDER BY shadowed by text-cast alias#43

Merged
github-actions[bot] merged 1 commit intomainfrom
fix/contracts-recent-orderby-shadowed-by-text-cast
May 8, 2026
Merged

fix(api): /contracts/recent ORDER BY shadowed by text-cast alias#43
github-actions[bot] merged 1 commit intomainfrom
fix/contracts-recent-orderby-shadowed-by-text-cast

Conversation

@satyakwok
Copy link
Copy Markdown
Contributor

Bug

SELECT first_seen_block::text creates an output column same-named as the base column but typed text. Postgres' ORDER BY resolves 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_block so 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

-- Before (bug):
ORDER BY first_seen_block DESC
→ rank 1 = 881639 (text "881639" sorts before "2575000")

-- After:
ORDER BY "addresses".first_seen_block DESC
→ rank 1 = 2575000 (bigint, correct)

tsc --noEmit clean.

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.
@github-actions github-actions Bot enabled auto-merge (squash) May 8, 2026 19:42
@github-actions github-actions Bot merged commit e2bfb73 into main May 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant