Здесь показаны различия между двумя версиями данной страницы.
| Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
|
postgres:show_tables [2021/11/04 16:30] 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 password. In 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> | </code> | ||
| - | Third, switch to a database e.g.., ''dvdrental'': | + | В-третьих, переключитесь на базу данных, например, 'dvdrental': |
| <code bash> | <code bash> | ||
| Строка 42: | Строка 21: | ||
| </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 bash> | ||
| 'postgres=# \dt | 'postgres=# \dt | ||
| + | </code> | ||
| - | </code> | ||
| - | Code language: PHP (php) | ||
| Output: | Output: | ||
| Строка 65: | Строка 41: | ||
| {{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:\\ | + | Чтобы получить дополнительную информацию о таблицах, вы можете использовать команду '' \\ dt + ''. Он добавит столбцы 'размер' и 'описание':\\ |
| - | + | ||
| - | + | ||
| - | + | ||
| <code bash> | <code bash> | ||
| Строка 80: | Строка 52: | ||
| ===== 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 bash> | ||
| Строка 89: | Строка 60: | ||
| {{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}}\\ | ||
| {{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 tables. If you omit the ''WHERE'' clause, you will get many tables including the system tables. | + | В этом запросе мы использовали условие в предложении WHERE для фильтрации системных таблиц. Если вы опустите предложение WHERE, вы получите много таблиц, включая системные таблицы. |