|
Hello Victor. As far as I understood, "use ..." is not valid command in Postgre SQL ... I have tried that.
|
|
|
|
|
_Flaviu wrote: As far as I understood, "use ..." is not valid command in Postgre SQL
I know.
But did you try the
\connect
|
|
|
|
|
That command is a Postgre SQL cmd line command, I cannot run it as SQL script, I have tried that.
Thank you.
|
|
|
|
|
If you are not using psql then how are you running your SQL?
|
|
|
|
|
Is about a C++ ODBC class which can run SQL scripts only.
|
|
|
|
|
|
|
Yes, I have tried:
SELECT *
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND
schemaname != 'information_schema';
but this script doesn't take into account a specific database. I don't understand how is relation between database and table, in Postgre SQL ...
|
|
|
|
|
That is not what the tutorial suggests. The summary states:
Quote: Summary: in this tutorial, you will learn how to show tables in PostgreSQL using psql tool and pg_catalog schema.
|
|
|
|
|
I realize that all available tables are below existing connection, which is the default database. And the default database must be choosen at the connection time. But yes, all databases could be listed in any connection.
Thank you for all your support.
modified 16-Jan-22 5:05am.
|
|
|
|
|
How can I list all tables from a specific database in PostGre SQL ?
Lets say I have 3 databases, and I have several tables in every one each of them. How can I retrieve the table names for every database I have, using SQL command ?
With following command:
SELECT datname FROM pg_database WHERE datistemplate = false
I got:
db_name
post_flaviu
postgres
test
Now, how can I find all tables under eevry db from above ?
modified 12-Jan-22 7:16am.
|
|
|
|
|
Feeding "postgresql list tables in database" into your search engine will produce a zillion useful answers.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Yes, I did. But I haven't found any SQL to tell me the tables for a specific database only .
|
|
|
|
|
You can get Postgres to tell you how to do that using the -E (display hidden queries) option to psql. So for example
$ psql -E -l
********* QUERY **********
SELECT d.datname as "Name",
pg_catalog.pg_get_userbyid(d.datdba) as "Owner",
pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding",
d.datcollate as "Collate",
d.datctype as "Ctype",
pg_catalog.array_to_string(d.datacl, E'\n') AS "Access privileges"
FROM pg_catalog.pg_database d
ORDER BY 1;
<hr />
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+-------------+-------------+-----------------------
template0 | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
test | ebacon | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
(3 rows) Likewise for the
\dt<dt> command inside psql. Then all you need to do is to figure out how to combine both queries into one.<br />
<div class="signature">Keep Calm and Carry On</div></dt>
|
|
|
|
|
Thank you. That query retrieve all databases. And for all tables from a database only ?
|
|
|
|
|
try
psql -E test -c "\dt". You can then take that output and combine with the previous one to get a listing of all tables across all databases.<br />
<div class="signature">Keep Calm and Carry On</div>
|
|
|
|
|
"get a listing of all tables across all databases"
That I already did. But doesn't help me, because I need the tables below a specific database, not all tables from all databases.
|
|
|
|
|
|
Thank you Richard. I have tried before, and now, the SQL from that page:
SELECT * FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema';
And as result I got all tables, from ALL databases.
Untitled6 — ImgBB[^]
|
|
|
|
|
But that is exactly what that command is supposed to do. You need to follow the instructions from the top of the page.
|
|
|
|
|
I am pretty close. And what SQL command should I use to select the database, and after that to call SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema' ?
I have tried:
USE database my_database
but seem to not work:
ERROR: syntax error at or near "USE";
Error while executing the query
You know, I need to all this programatically, using SQL commands, not using Postgre tools.
modified 12-Jan-22 12:30pm.
|
|
|
|
|
Sorry, I do not have a system available to test this. However, I do not see any instruction concerning a USE statement in the tutorial on that page.
|
|
|
|
|
I have installed a WampServer, and when I wanted to try it, seem that localhost is not available:
Untitled4 — ImgBB[^]
I noticed that mysql and mariadb services are running:
Untitled2 — ImgBB[^]
I only started localhost from here:
Untitled3 — ImgBB[^]
Also, other options from that menu are not working either: PHPMyAdmin , etc. What I should do to use MySQL database ? In fact, I only need to setup a ODBC source for MySQL database from WampServer , that's all.
modified 7-Jan-22 2:58am.
|
|
|
|
|
The web server is "Apache" - make sure you start that, then the web-based admin things should work (assuming it is configured correctly).
|
|
|
|
|
Ohh, I tried that before, but didn't start it:
Untitled5 — ImgBB[^]
I'll check the log to see why.
|
|
|
|