pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Flaviu2 <flaviu2@yahoo.com>
To: Ray O'Donnell <ray@rodonnell.ie>
To: Thomas Boussekey <thomas.boussekey@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: List all tables from a specific database
Date: Fri, 14 Jan 2022 12:19:28 +0000 (UTC)
Message-ID: <885647530.630187.1642162768711@mail.yahoo.com> (raw)
In-Reply-To: <CALUeYmfm5ASkR4c60jy9zX0wEQxtBOhZYoOa=LtBP_OSBr9jKg@mail.gmail.com>
References: <754992290.610416.1642156769536.ref@mail.yahoo.com>
	<754992290.610416.1642156769536@mail.yahoo.com>
	<424c1084-1e65-8e06-7f80-efe2a2b819e7@rodonnell.ie>
	<CALUeYmfm5ASkR4c60jy9zX0wEQxtBOhZYoOa=LtBP_OSBr9jKg@mail.gmail.com>

 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.
Flaviu.
    On Friday, January 14, 2022, 02:08:22 PM GMT+2, Thomas Boussekey <thomas.boussekey@gmail.com> wrote:  
 
 

Le ven. 14 janv. 2022 à 12:04, Ray O'Donnell <ray@rodonnell.ie> a écrit :

On 14/01/2022 10:39, Flaviu2 wrote:
> I work on a project that use Postgre SQL, and I have 0 experience in 
> this regard. I hope to get help here. I need two SQL scripts for Postgre:
> 
> 1. Get all databases, which I aquired already:
> 
> *SELECT datname FROM pg_database WHERE datistemplate = false*
> 
> This one is functional, it's ok.
> 
> 2. Now, I need to find all tables *under a specific* database. This one 
> I don't know how to achieve it. Can you help me here ? It is possible ?



If it's any help, running psql with the -E switch will show you the SQL 
which psql generates... so then (within psql) issuing the \dt command to 
list tables will show you the SQL used.

Ray.


Hello,You can use this SQL command to view all the standard table (known as relations):
SELECT relname FROM pg_class WHERE relkind = 'r';
 And this one for partitioned tables (if you use them):
SELECT relname FROM pg_class WHERE relkind = 'p'; 
HTH,Thomas


-- 
Raymond O'Donnell // Galway // Ireland
ray@rodonnell.ie



  

view thread (10+ messages)  latest in thread

Message-ID: <885647530.630187.1642162768711@mail.yahoo.com>
Permalink:  ../885647530.630187.1642162768711@mail.yahoo.com/
Also on:    postgresql.org/message-id/885647530.630187.1642162768711@mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: flaviu2@yahoo.com, ray@rodonnell.ie, thomas.boussekey@gmail.com
  Subject: Re: List all tables from a specific database
  In-Reply-To: <885647530.630187.1642162768711@mail.yahoo.com>
  References: <754992290.610416.1642156769536.ref@mail.yahoo.com> <754992290.610416.1642156769536@mail.yahoo.com> <424c1084-1e65-8e06-7f80-efe2a2b819e7@rodonnell.ie> <CALUeYmfm5ASkR4c60jy9zX0wEQxtBOhZYoOa=LtBP_OSBr9jKg@mail.gmail.com> <885647530.630187.1642162768711@mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox