SQLite Forum

Identifying attached database
Login
Note that the return order does not reflect the unqualified table search order.

The query **select row_number() over (order by name != 'temp', seq) as search, * from pragma_database_list;** will return the results with a "search" column that reflects the unqualified table search order.

```
>sqlite
-- Loading resources from C:\Users\KMedcalf/.sqliterc
SQLite version 3.34.0 2020-10-05 19:05:20
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> attach 'a.db' as a;
sqlite> attach 'b.db' as b;
sqlite> detach a;
sqlite> attach 'c.db' as c;
sqlite> select row_number() over (order by name != 'temp', seq) as search, * from pragma_database_list;
┌────────┬─────┬──────┬────────────────────────┐
│ search │ seq │ name │          file          │
├────────┼─────┼──────┼────────────────────────┤
│ 1      │ 1   │ temp │                        │
│ 2      │ 0   │ main │                        │
│ 3      │ 2   │ _tz_ │ d:\source\sqlite\tz.db │
│ 4      │ 3   │ b    │ D:\b.db                │
│ 5      │ 4   │ c    │ D:\c.db                │
└────────┴─────┴──────┴────────────────────────┘
sqlite>
```