How to grant select to all tables in PostgreSQL

In this article, we will see how to grant select to all tables in PostgreSQL. We can grant select privilege in PostgreSQL by using grant command.

Syntax to grant select to all tables in PostgreSQL:
Continue reading How to grant select to all tables in PostgreSQL

How to do schema only backup and restore in PostgreSQL?

In this article, we will see how to do schema only backup and restore in PostgreSQL.
Schema only backup contains only objects definition like table definition.

To take a schema level backup in PostgreSQL database and restore on the another database, we use pg_dump utility with the option –schema-only or -s. If we gave –schema-only means, it dumps only the object definitions (schema), not data.
Continue reading How to do schema only backup and restore in PostgreSQL?

How to move tables from one schema to another in PostgreSQL

In this article, we will see how to move tables from one schema to another in PostgreSQL. We can move the tables from one schema to another by using alter table command. Schemas are database objects. Same schema can be exists in different. But, tables of schema are different.

Syntax:

ALTER TABLE table_name SET SCHEMA schema_name;

Examples to move tables from one schema to another in PostgreSQL:
Continue reading How to move tables from one schema to another in PostgreSQL

How to set permanent schema path to user in PostgreSQL

In this article, we will see how to set permanent schema path to user in PostgreSQL with examples. We can set it by using ALTER ROLE command.

Syntax to set permanent schema path to user in PostgreSQL:
Continue reading How to set permanent schema path to user in PostgreSQL

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

ERROR: cannot drop schema because other objects depend on it

In this article, we are going to see the solution for “ERROR: cannot drop schema because other objects depend on it”.

drop schema james;

ERROR cannot drop schema because other objects depend on it

Reason:
So, if the schema is not empty and you want to remove the schema and its objects, you must use the CASCADE option.

Solution:
Continue reading ERROR: cannot drop schema because other objects depend on it

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 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 get list of all schemas in PostgreSQL

In this article, we will see how to get list of all schemas in PostreSQL. We can get list of schema by querying against information_schema or pg_catalog views or using meta-command \dn[options].

1. To get list of all schemas in PostgreSQL using SQL query:
Continue reading How to get list of all schemas in PostgreSQL