Skip to content

Commit e2bfb73

Browse files
authored
fix(api): /contracts/recent ORDER BY shadowed by text-cast alias (#43)
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. Co-authored-by: satyakwok <satyakwok@users.noreply.github.com>
1 parent 0ab6290 commit e2bfb73

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

apps/api/src/routes/native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export function registerNativeRoutes(
304304
code_hash
305305
FROM ${addresses}
306306
WHERE is_contract = true
307-
ORDER BY first_seen_block DESC
307+
ORDER BY ${addresses}.first_seen_block DESC
308308
LIMIT ${limit}
309309
`
310310
);

0 commit comments

Comments
 (0)