| From: | Julien Rouhaud <rjuju123(at)gmail(dot)com> | 
|---|---|
| To: | Flaviu2 <flaviu2(at)yahoo(dot)com> | 
| Cc: | Ray O'Donnell <ray(at)rodonnell(dot)ie>, Thomas Boussekey <thomas(dot)boussekey(at)gmail(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> | 
| Subject: | Re: List all tables from a specific database | 
| Date: | 2022-01-14 12:26:09 | 
| Message-ID: | 20220114122609.y3h5wcleromhvbn4@jrouhaud | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Hi,
On Fri, Jan 14, 2022 at 12:19:28PM +0000, Flaviu2 wrote:
>  Thanks a lot.
> Maybe I am not far from a solving solution. So, if I create a database, lets say (SQL script):
> CREATE database mydb3;
> How can I create a table under mydb3 ? Because, if I run:
> SELECT relname FROM pg_class WHERE relkind = 'r';
> 
> Got me all tables, but I don't know the database under were created.
On postgres all relations, functions and so on are specific to a specific
database, and only accessible when connected on that specific database.
So if you want to create a table in mydb3, or see the list of tables in that
database, you need to connect to mydb3.
If needed, you can get the current database with the current_database()
function, e.g.:
=# SELECT current_database();
 current_database
------------------
 postgres
(1 row)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Flaviu2 | 2022-01-14 12:42:22 | Re: List all tables from a specific database | 
| Previous Message | Flaviu2 | 2022-01-14 12:19:28 | Re: List all tables from a specific database |