• How to Switch Database in psql?

    How to Switch Database in psql?

    Sometimes we host multiple database in single PostgreSQL instance and we need to switch between them in psql. For this article, i created two databases: test1 and test2 will be our database to switch between. Tip of The Day You can use \l shortcut to list database and database templates in PostgreSQL. Also \list can…

  • How to Drop All Tables in a PostgreSQL Database?

    How to Drop All Tables in a PostgreSQL Database?

    Today, we will discuss a very dangerous question. How to drop all tables in a PostgreSQL database? This is a very dangerous question, as i see, thats very popular question, i would like to bring it here. The Wrong Way On internet you can find statements like: And grant permissions again. I call this method…

  • How to Change a PostgreSQL User Password

    How to Change a PostgreSQL User Password

    That command is one of the simplest and most common one around different database engines. (Excluding Db2-like Db engines, because it uses OS to validate passwords) Alter is the command we use to change / update an attribute or object in database engines. So simply, change user’s password in PostgreSQL as: Of course, you need…

  • How to Select Fist Row in Each Group?

    How to Select Fist Row in Each Group?

    Sometimes we need maximums of each group, or minimums of each group in SQL. In PostgeSQL, you can use DISTINCT ON statement to achieve this. In PostgreSQL’s documentation DISTINCT ON statement explained as: SELECT DISTINCT ON ( expression [, …] ) keeps only the first row of each set of rows where the given expressions…

  • How to Exit psql Command Line

    How to Exit psql Command Line

    PostgreSQL provides an interactive command line utility for it’s users. Mostly it’s called as psql. You can run SQL queries from psql command line tool, also statements like \d too. In this article we are going to cover how to exit from PostgreSQL command line. Answer of question “how to exit from PostgreSQL command line?”…

  • Describe Table in PostgreSQL

    Describe Table in PostgreSQL

    Describe table is a commonly used query in MySQL. In PostreSQL there isn’t a direct equivalent of this command. In PostgreSQL command line (pgsql) you can use: Some cloud provider use a special build or they don’t directly provide pg interface, therefore you can’t use \d \dt commands. You might need an SQL alternative to…

  • Show tables in PostgreSQL

    Show tables in PostgreSQL

    How to show tables in PostgreSQL is a common question for beginners. In this article we will discuss showing tables in PostgreSQL. In PostgreSQL all information about DB objects stored under information_schema. You can use information_schema.tables table to list and show tables. A simple query to list all tables and schemas: If you want to…

  • PostgreSQL for Beginners

    PostgreSQL for Beginners

    Hello, this is a test purpose article about PostgreSQL for beginners. PostgreSQL is a powerful, open-source relational database management system (RDBMS). It is a popular choice for a wide range of applications, including web applications, data warehousing, and big data analytics. PostgreSQL is known for its reliability, scalability, and flexibility. This blog article is designed…