-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: finish testing index creation
- Loading branch information
1 parent
8cc5967
commit 95c5e2a
Showing
5 changed files
with
142 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from asyncpg import Record | ||
|
||
from udata_hydra import context | ||
|
||
|
||
async def get_columns_with_indexes(table_name: str) -> list[Record] | None: | ||
""" | ||
Get the columns of a table which have indexes | ||
Return a list of records with the following columns: | ||
- table_name | ||
- index_name | ||
- column_name | ||
""" | ||
pool = await context.pool() | ||
async with pool.acquire() as connection: | ||
q = """ | ||
SELECT | ||
t.relname as table_name, | ||
i.relname as index_name, | ||
a.attname as column_name | ||
FROM | ||
pg_class t, | ||
pg_class i, | ||
pg_index ix, | ||
pg_attribute a | ||
WHERE | ||
t.oid = ix.indrelid | ||
and i.oid = ix.indexrelid | ||
and a.attrelid = t.oid | ||
and a.attnum = ANY(ix.indkey) | ||
and t.relkind = 'r' | ||
and t.relname = $1 | ||
ORDER BY | ||
t.relname, | ||
i.relname; | ||
""" | ||
return await connection.fetch(q, table_name) |