programing

postgresql information_schema에 모든 테이블 나열

starjava 2023. 6. 6. 00:22
반응형

postgresql information_schema에 모든 테이블 나열

Postgre 내의 모든 테이블을 나열하는 가장 좋은 방법은 무엇입니까?SQL의 information_schema?

명확하게 하기: 빈 DB로 작업 중입니다(내 테이블을 추가하지 않았습니다). 그러나 모든 테이블을 보고 싶습니다.information_schema구조.

당신은 그냥 도망칠 수 있을 겁니다select * from information_schema.tables특정 데이터베이스에 대해 Postgres에서 관리 중인 모든 테이블의 목록을 가져옵니다.

다음을 추가할 수도 있습니다.where table_schema = 'information_schema'정보 스키마의 테이블만 볼 수 있습니다.

표를 나열하려면 다음을 사용합니다.

SELECT table_name FROM information_schema.tables WHERE table_schema='public'

사용자가 만든 테이블만 나열됩니다.

\dt information_schema.

psql 내에서, 괜찮을 것입니다.

또한 "\z" 명령어는 대화형 psql 세션 내에서 테이블을 나열하는 좋은 방법입니다.

예를 들면

# psql -d mcdb -U admin -p 5555
mcdb=# /z
                           Access privileges for database "mcdb"
 Schema |              Name              |   Type   |           Access privileges
--------+--------------------------------+----------+---------------------------------------
 public | activities                     | table    |
 public | activities_id_seq              | sequence |
 public | activities_users_mapping       | table    |
[..]
 public | v_schedules_2                  | view     | {admin=arwdxt/admin,viewuser=r/admin}
 public | v_systems                      | view     |
 public | vapp_backups                   | table    |
 public | vm_client                      | table    |
 public | vm_datastore                   | table    |
 public | vmentity_hle_map               | table    |
(148 rows)

1.information_vlan.vlan에서 information_vlan 및 pg_vlan의 테이블과 뷰를 모두 가져옵니다.

select * from information_schema.tables

2.테이블 및 뷰가 특정 스키마에 속함

select * from information_schema.tables
    where table_schema not in ('information_schema', 'pg_catalog')

3.테이블만 가져오기(예: \dt)

select * from information_schema.tables
    where table_schema not in ('information_schema', 'pg_catalog') and
    table_type = 'BASE TABLE'

또한 사용할 수 있습니다.

select * from pg_tables where schemaname = 'information_schema'

일반적으로 모든 pg* 테이블을 사용하면 권한에 제한되지 않고 DB의 모든 내용을 볼 수 있습니다(물론 테이블에 액세스할 수 있는 경우).

개인 스키마의 경우'xxx'postgresql:

SELECT table_name FROM information_schema.tables 
 WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'

없이.table_type = 'BASE TABLE'테이블과 뷰를 나열합니다.

빠르고 더러운 한 줄 쿼리를 원하는 경우:

select * from information_schema.tables

psql을 열지 않고 쿼리 도구에서 직접 실행할 수 있습니다.

(다른 게시물에서는 더 구체적인 정보_schema 쿼리를 제안하지만, 새로운 사람으로서, 이 한 줄짜리 쿼리가 테이블을 이해하는 데 도움이 된다는 것을 알게 되었습니다.)

select * from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE'

테이블만 확보하기 위해

언급URL : https://stackoverflow.com/questions/2276644/list-all-tables-in-postgresql-information-schema

반응형