There are several ways that we can list all indexes in PostgreSQL. These include utilizing various system catalog views and psql
commands. Below are five options for returning a list of indexes in PostgreSQL, along with examples of how to filter the results by index name, table name, and other criteria.
Tag: psql
PostgreSQL \di Command Explained
The \di
command can be used to list indexes in the current database when using psql
(PostgreSQL’s command-line tool). This meta-command can display all indexes, or just indexes that match certain patterns. Here’s an in-depth explanation of how \di
works, its options, and examples of its various uses.
PostgreSQL \dt Command Explained
When using PostgreSQL’s psql
command line tool, we can use the \dt
command to get a list of tables. This meta-command can display all tables, or just tables that match certain patterns. Below is an overview of how \dt
works, its options, and examples of its various uses.
5 Ways to Enable Vertical Output in psql
When we use psql
to write SQL queries in PostgreSQL, we’ll usually see the results presented as a table, with columns displayed vertically and rows running horizontally. But it is possible to change this so that the columns are displayed horizontally and the rows run vertically.
This can be useful for when the number of columns causes the results to be wider than our psql
display, and may cause the rows to wrap to the next line.
Here are five ways we can change the display to vertical output, otherwise known as expanded display.
Continue readingAdd Minutes to a Time Value in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more minutes to a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also add minutes to a date
value or a date
and time
combination.
Subtract Seconds from a Time Value in PostgreSQL
In PostgreSQL, we can use the -
operator to subtract one or more seconds from a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also subtract seconds from a date
value or a date
and time
combination.
Add Seconds to a Time Value in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more seconds to a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also add seconds to a date
value or a date
and time
combination.
PostgreSQL CASE Expression
In PostgreSQL, the CASE
expression compares a list of conditions and returns one of multiple possible result expressions.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
2 Ways to List All Tables in a PostgreSQL Database
Here are a couple of options for getting a list of tables in a database in PostgreSQL.
The first option is a psql
command, the second involves querying an information schema view.
Subtract Hours from a Time Value in PostgreSQL
In PostgreSQL, we can use the -
operator to subtract one or more hours from a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also subtract hours from a date
value or a date
and time
combination.