Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command for listing indices #3

Open
owenconti opened this issue May 2, 2020 · 4 comments
Open

Add command for listing indices #3

owenconti opened this issue May 2, 2020 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@owenconti
Copy link
Member

Add new command for listing indices:

schema:indices {table}

@owenconti owenconti added the help wanted Extra attention is needed label May 2, 2020
@willvincent
Copy link
Contributor

willvincent commented May 2, 2020

For postgres:

SELECT kcu.column_name as Field, 
       i.indexname as Index,
       i.indexdef as Definition 
FROM pg_indexes i
JOIN information_schema.key_column_usage kcu ON kcu.constraint_name = i.indexname
WHERE i.tablename = 'users';

Outputs:

Field Index Definition
id users_pkey CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)
email users_email_unique CREATE UNIQUE INDEX users_email_unique ON public.users USING btree (email)

@willvincent
Copy link
Contributor

@dinhquochan
Copy link
Contributor

For MySQL:

SHOW INDEX FROM users;

Output:

+-------+------------+-----------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name                    | Seq_in_index | Column_name   | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+-------+------------+-----------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| users |          0 | PRIMARY                     |            1 | id            | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| users |          0 | users_email_unique          |            1 | email         | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| users |          1 | users_user_group_id_foreign |            1 | user_group_id | A         |           0 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
+-------+------------+-----------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
3 rows in set (0.01 sec)

@willvincent
Copy link
Contributor

there are several other attributes that could be included in the postgres select, but nothing else seemed super relevant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants