🧚 주목! Beekeeper Studio는 빠르고 현대적이며 오픈 소스 데이터베이스 GUI입니다 다운로드
April 8, 2024 작성자: Matthew Rathbone

In this article, we are going to delve into one of the in-built systems within PostgreSQL known as the information_schema.

What is Information_Schema?

Information_schema is a system catalog that forms a standard set of views which contains information about the PostgreSQL database objects, essentially, it’s a meta-database that holds information about your current database. It’s present in all standards-compliant SQL database engines which makes it quite useful when migrating.

It must be noted that the information_schema is read-only and does not support the insertion of new information or alteration of existing data. Let’s start exploring different views within the information_schema that can be instrumental to users for various practices.

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

The code is compatible with all PostgreSQL versions.
Upon execution, this code will yield a list of all views available to users within the information_schema.

Why Use Information_Schema?

The information_schema is significantly crucial when you are trying to work more effectively with database structures, primarily, when relating to:

  • Tables
  • Columns
  • Indexes
  • Triggers
  • Constraints
  • Schemas

Information_Schema.Tables

The information_schema.tables view contains details about all tables in the connected database.

SELECT table_name 
FROM information_schema.tables 
WHERE table_type = 'BASE TABLE' 
AND table_schema NOT IN ('pg_catalog', 'information_schema');

The code is compatible with all PostgreSQL versions. The output here will be a list of all base tables within your database.

Information_Schema.Columns

The information_schema.columns view is where you can fetch details about column specifics in your database.

SELECT table_name, column_name, data_type 
FROM information_schema.columns 
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
AND table_name   = 'your_table';

The code is compatible with any PostgreSQL version. Replace ‘your_table’ with your table name to get a list of all columns with their data types within the specified table.

Information_Schema.Triggers

Information about triggers can be helpful when debugging or in understanding dependencies. The information_schema.triggers view is used to fetch details about triggers linked to the database.

SELECT event_object_table, trigger_name, action_statement, action_timing 
FROM information_schema.triggers;

This code configuration, compatible with all PostgreSQL versions, will yield the table name, trigger name, the trigger action, and its timing.

Information_Schema.Key_Column_Usage

The information_schema.key_column_usage view provides information making it easier to understand foreign-key relationships in your database.

SELECT constraint_name, table_name, column_name, ordinal_position
FROM information_schema.key_column_usage
WHERE table_name = 'your_table';

Replace ‘your_table’ with your table name and execute the code compatible with all PostgreSQL versions, to get the constraint_name, table_name, column_name, and ordinal_position for every key in the specified table.

Conclusion

In this tutorial, we unravelled the details about PostgreSQL’s information_schema. By leveraging the views in the information_schema, you can attain enhanced control and derive sharper insights about your database’s structure and elements. If you are moving to PostgreSQL from another SQL database, you will find information_schema views particularly handy since they are a standard part of SQL.

Your adventure with PostgreSQL does not end here. Stay tuned for upcoming guides delving deeper into the vast universe of PostgreSQL, where we would cover more advanced topics, tips and tricks.

Beekeeper Studio는 무료 & 오픈 소스 데이터베이스 GUI입니다

제가 사용해 본 최고의 SQL 쿼리 & 편집기 도구입니다. 데이터베이스 관리에 필요한 모든 것을 제공합니다. - ⭐⭐⭐⭐⭐ Mit

Beekeeper Studio는 빠르고 직관적이며 사용하기 쉽습니다. Beekeeper는 많은 데이터베이스를 지원하며 Windows, Mac, Linux에서 훌륭하게 작동합니다.

Beekeeper의 Linux 버전은 100% 완전한 기능을 갖추고 있으며, 기능 타협이 없습니다.

사용자들이 Beekeeper Studio에 대해 말하는 것

★★★★★
"Beekeeper Studio는 제 예전 SQL 워크플로를 완전히 대체했습니다. 빠르고 직관적이며 데이터베이스 작업을 다시 즐겁게 만들어 줍니다."
— Alex K., 데이터베이스 개발자
★★★★★
"많은 데이터베이스 GUI를 사용해 봤지만, Beekeeper는 기능과 단순함 사이의 완벽한 균형을 찾았습니다. 그냥 작동합니다."
— Sarah M., 풀스택 엔지니어

SQL 워크플로를 개선할 준비가 되셨나요?

download 무료 다운로드