Инструменты пользователя

Инструменты сайта


postgres:show_tables

Различия

Здесь показаны различия между двумя версиями данной страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
postgres:show_tables [2021/11/04 16:28]
werwolf
postgres:show_tables [2023/01/12 12:18] (текущий)
Строка 1: Строка 1:
 ====== PostgreSQL Show Tables ====== ====== PostgreSQL Show Tables ======
- 
-If this PostgreSQL Tutorial saves you hours of work, please whitelist it in your ad blocker 😭 and 
- 
-Donate Now 
- 
-to help us вќ¤пёЏ pay for the web hosting fee and CDN to keep the website running. 
- 
-**Summary**:​ in this tutorial, you will learn how to show tables in PostgreSQL using ''​psql''​ tool and ''​pg_catalog''​ schema. 
- 
-If you are coming from MySQL, you may want to use the popular ''​SHOW TABLES''​ statement that displays all tables in a specific database. 
- 
-PostgreSQL does not support the ''​SHOW TABLES''​ statement directly but provides you with an alternative. 
- 
-===== PostgreSQL show tables using psql ===== 
- 
-First, connect to PostgreSQL using psql tool. 
- 
- 
  
  
 +Сначала подключитесь к PostgreSQL с помощью инструмента psql.
  
 <code bash> <code bash>
Строка 25: Строка 8:
 </​code>​ </​code>​
  
-The ''​-U'' ​flag stands for the **u**ser and ''​-W'' ​option requires you to provide the passwordIn this command, you use the ''​postgres''​ user to log in to the PostgreSQL ​database server. +''​-U''​флаг означает ​**u**ser and ''​-W'' ​опция требует,​ чтобы вы предоставили парольВ этой команде вы используете пользователя ​postgres ​для входа на сервер базы данных ​PostgreSQL.
- +
-Secodn, enter the password for the user ''​postgres''​ and press the ''​Enter''​ keywboard:​ +
- +
- +
- +
  
 +Во-вторых,​ введите пароль для пользователя postgres и нажмите на клавиатуре Enter:
 <code bash> <code bash>
 Password for user postgres: postgres=# Password for user postgres: postgres=#
-Code language: PHP (php) 
 </​code>​ </​code>​
  
-Thirdswitch to a database e.g..''​dvdrental'': +В-третьихпереключитесь на базу данных,​ например, '​dvdrental':​
- +
- +
- +
  
 <code bash> <code bash>
 postgres=# \c dvdrental You are now connected to database "​dvdrental"​ as user "​postgres"​. postgres=# \c dvdrental You are now connected to database "​dvdrental"​ as user "​postgres"​.
-Code language: PHP (php) 
 </​code>​ </​code>​
  
-Note that you can connect to a specific database when you log in to the PostgreSQL ​database server+<​note>​ 
- +Обратите внимание,​ что вы можете подключиться к определенной базе данных при входе на сервер базы данных ​PostgreSQL:​ 
-''​ +</​note>​
 <code bash> <code bash>
 $ psql -U postgres -d dvdrental $ psql -U postgres -d dvdrental
 </​code>​ </​code>​
  
-In this command, ​''​-d'' ​flag means **d**atabase. ​In this command, you connect to the ''​dvdrental''​ datbase using the ''​postgres''​ user.+В этой команде флаг ​''​ -d '' ​означает ​** d ** atabase. ​В этой команде вы подключаетесь к базе данных ​dvdrental ​с помощью пользователя ​postgres. 
 +В-третьих,​ используйте команду \\ dt из командной строки PostgreSQL для отображения таблиц в базе данных dvdrental:
  
-Third, use the ''​\dt''​ command from the PostgreSQL command prompt to show tables in the ''​dvdrental''​ database: +<​code ​bash>
- +
- +
- +
- +
-<​code>​+
 '​postgres=#​ \dt '​postgres=#​ \dt
 +</​code>​
  
-</​code>​ 
-Code language: PHP (php) 
 Output: Output:
  
-{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables-in-psql-using-dt.png?​397x383}}{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables-in-psql-using-dt.png?​397x383}}To get more information on tables, you can use the ''​\dt+''​ command. It will add the ''​size''​ and ''​description''​ columns:+{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables-in-psql-using-dt.png?​397x383}} ​\\ 
 +\\ 
 +{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables-in-psql-using-dt.png?​397x383}}\\
  
 +Чтобы получить дополнительную информацию о таблицах,​ вы можете использовать команду ''​ \\ dt + ''​. Он добавит столбцы '​размер'​ и '​описание':​\\
  
- +<​code ​bash>
- +
- +
-<​code>​+
 postgres=# \dt+ postgres=# \dt+
 </​code>​ </​code>​
 +\\
 +{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables-in-psql.png?​643x386}}\\
 +{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables-in-psql.png?​643x386}}\\
  
-{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables-in-psql.png?​643x386}}{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables-in-psql.png?​643x386}}===== PostgreSQL show tables using pg_catalog schema =====+===== PostgreSQL show tables using pg_catalog schema =====
  
-Another way to show tables in PostgreSQL ​is to use the ''​SELECT''​ statement to query data from the PostgreSQL ​catalog as follows:+Другой способ показать таблицы в PostgreSQL ​- использовать оператор ​SELECT ​для запроса данных из каталога ​PostgreSQL ​следующим образом:
  
- +<​code ​bash>
-<​code>​+
 SELECT * FROM pg_catalog.pg_tables WHERE schemaname != '​pg_catalog'​ AND schemaname != '​information_schema';​ SELECT * FROM pg_catalog.pg_tables WHERE schemaname != '​pg_catalog'​ AND schemaname != '​information_schema';​
 </​code>​ </​code>​
  
-{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables.png?​821x454}}{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables.png?​821x454}}In this query, we used a condition in the ''​WHERE''​ clause to filter system tablesIf you omit the ''​WHERE''​ clauseyou will get many tables including the system tables.+{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables.png?​821x454}}\\ 
 +{{https://​www.postgresqltutorial.com/​wp-content/​uploads/​2020/​07/​PostgreSQL-show-tables.png?​821x454}}\\ 
 +В этом запросе мы использовали условие в предложении ​WHERE для фильтрации системных таблицЕсли вы опустите предложение ​WHERE, ​вы получите много таблиц,​ включая системные таблицы.
  
  
postgres/show_tables.1636032491.txt.gz · Последние изменения: 2023/01/12 12:17 (внешнее изменение)