Programming

모든 테이블 이름을 나열하는 PostgreSQL 쿼리?

procodes 2020. 6. 5. 22:42
반응형

모든 테이블 이름을 나열하는 PostgreSQL 쿼리?


Postgres DB의 모든 테이블을 나열하는 데 사용할 수있는 쿼리가 있습니까?

나는 다음과 같은 하나의 쿼리를 시도했다.

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

그러나이 쿼리는 뷰도 반환합니다.

뷰가 아닌 테이블 이름 만 얻을 수 있습니까?


이 검색어에 대한 설명은 무엇입니까 ( manual 의 설명에 따라 )?

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

데이터베이스 목록을 원한다면

SELECT datname FROM pg_database WHERE datistemplate = false;

모든 데이터베이스의 현재 pg 설치에서 테이블 목록을 원하는 경우

SELECT table_schema,table_name FROM information_schema.tables
ORDER BY table_schema,table_name;

원하는 데이터베이스를 사용하여 postgres 터미널을 엽니 다.

psql dbname (run this line in a terminal)

그런 다음 postgres 환경에서이 명령을 실행하십시오.

\d

이름별로 모든 테이블을 설명합니다. 기본적으로 이름 오름차순으로 된 테이블 목록입니다.

그런 다음 필드별로 테이블을 설명하기 위해 시도해 볼 수 있습니다.

\d tablename.

도움이 되었기를 바랍니다.


select 
 relname as table 
from 
 pg_stat_user_tables 
where schemaname = 'public'

select 
  tablename as table 
from 
  pg_tables  
where schemaname = 'public'
  • pg_tables 에 대해서 더 읽어보세요.

어떻게 그냥주는 약 \dtpsql? https://www.postgresql.org/docs/current/static/app-psql.html을 참조 하십시오 .


이 시도:

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

이것은 작동합니다!

참고 URL : https://stackoverflow.com/questions/14730228/postgresql-query-to-list-all-table-names

반응형