How to find list tables in a PostgreSQL schema

In this article, we will see how to find list tables in a PostgreSQL schema with examples.

We can find the list of tables in a PostgreSQL schema using meta-command or by using SQL statement by querying against table pg_tables.

Find list tables in a PostgreSQL schema using meta-command: Continue reading How to find list tables in a PostgreSQL schema

How to rename table in PostgreSQL

In this article, we will see how to rename table in PostgreSQL. We can rename a table by using alter command.

Syntax to rename table in PostgreSQL:

ALTER TABLE table_name RENAME TO new_table_name;

Examples:
Continue reading How to rename table in PostgreSQL

How to insert values into a table from a select query in PostgreSQL

In this article, we will see how to insert values into a table from a select query in PostgreSQL.

Syntax to Copy one table data to another in PostgreSQL:

insert into table_name select * from another_table where condition;

Continue reading How to insert values into a table from a select query in PostgreSQL

PostgreSQL Create table from existing table

In this article, we are going to see how to Create PostgreSQL table structure from existing table with examples.

PostgreSQL query to copy the structure of an existing table to create another table.

create table table_name as select * from exsting_table_name where 1=2;

Continue reading PostgreSQL Create table from existing table

How to find number of tables in PostgreSQL Database

In this article, we will see how to find number of tables in PostgreSQL Database.

The number of tables in a relational database is good measure of the complexity of a database, so it is a simple way to get know any database.
Continue reading How to find number of tables in PostgreSQL Database

How to grant permissions on all tables to a user in PostgreSQL

In this article, we will see how to grant permissions on all tables to a user in PostgreSQL.

Syntax:

GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO user_name;

Examples:

1. First grant CONNECT to database using below syntax.
Continue reading How to grant permissions on all tables to a user in PostgreSQL

How to import CSV file data into PostgreSQL table

In this article, we will see How to import CSV file data into PostgreSQL table. It is nothing but loading data from a spreadsheet.

1. Create table

CREATE TABLE student(sno int primary key, sname varchar(50), sage int, dob date);

Continue reading How to import CSV file data into PostgreSQL table

PostgreSQL describe table

In this article, we will see PostgreSQL describe table. Which means we will get the table structure in of PostgreSQL table.

We can get the table structure by using meta command select query.

PostgreSQL describe table using meta command:
Continue reading PostgreSQL describe table

How to check if a table exists in PostgreSQL Schema or not

In this article, we are going to check whether a table exists in PostgreSQL schema or not. Following queries are used in this article. If table exists then output will be ‘t’ otherwise ‘f’.

Query to check tables exists or not in PostgreSQL Schema or not 1:

SELECT EXISTS( SELECT * FROM information_schema.tables WHERE table_schema = 'schemaname' AND table_name = 'tablename' );

Query to check tables exists or not in PostgreSQL Schema or not 2:
Continue reading How to check if a table exists in PostgreSQL Schema or not

How to Copy table from one database to another in PostgreSQL

In this article, we will see how to Copy table from one database to another in PostgreSQL. We can copy a table from one database to other using pg_dump tool.

Copy table from one database to another in PostgreSQL:

If table is empty then, run the below command from Linux.

pg_dump -t table_to_copy source_db | psql target_db

Continue reading How to Copy table from one database to another in PostgreSQL