From 8b220596d614eddc5e16a5ded56b9e36f0468370 Mon Sep 17 00:00:00 2001 From: satyakwok Date: Fri, 8 May 2026 21:41:48 +0200 Subject: [PATCH] fix(api): /contracts/recent ORDER BY shadowed by text-cast alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- apps/api/src/routes/native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/routes/native.ts b/apps/api/src/routes/native.ts index d7c14dc..a6b2005 100644 --- a/apps/api/src/routes/native.ts +++ b/apps/api/src/routes/native.ts @@ -304,7 +304,7 @@ export function registerNativeRoutes( code_hash FROM ${addresses} WHERE is_contract = true - ORDER BY first_seen_block DESC + ORDER BY ${addresses}.first_seen_block DESC LIMIT ${limit} ` );