例如,如何在 shell 本身中按“Column”中的值对下面的输出进行排序psql
?
my_db=> \d auth_user
Table "public.auth_user"
Column | Type | Collation | Nullable | Default
--------------+--------------------------+-----------+----------+---------------------------------------
id | integer | | not null | nextval('auth_user_id_seq'::regclass)
is_superuser | boolean | | not null |
username | character varying(150) | | not null |
first_name | character varying(150) | | |
last_name | character varying(150) | | not null |
email | character varying(254) | | |
is_staff | boolean | | not null | false
is_active | boolean | | not null | false
password | character varying(128) | | |
last_login | timestamp with time zone | | |
date_joined | timestamp with time zone | | |
Indexes:
"auth_user_pkey" PRIMARY KEY, btree (id)
"auth_user_username_6821ab7c_like" btree (username varchar_pattern_ops)
"auth_user_username_key" UNIQUE CONSTRAINT, btree (username)
我知道这在 shell 之外很容易做到psql
,例如在 Bash 中,
$ psql -U postgres -h localhost -d my_db -c '\d auth_user' | grep '^.*|' | sort -t'|' -k1
Column | Type | Collation | Nullable | Default
date_joined | timestamp with time zone | | |
email | character varying(254) | | |
first_name | character varying(150) | | |
id | integer | | not null | nextval('auth_user_id_seq'::regclass)
is_active | boolean | | not null | false
is_staff | boolean | | not null | false
is_superuser | boolean | | not null |
last_login | timestamp with time zone | | |
last_name | character varying(150) | | not null |
password | character varying(128) | | |
username | character varying(150) | | not null |
但我很好奇这是否可以完成psql
。