How to Use the Postgres MIN Function on an ObjectRocket instance

Have a Database Problem? Speak with an Expert for Free
Get Started >>

Introduction

This tutorial will explain how to use the Postgres MIN function on an ObjectRocket instance. The PostgreSQL MIN function is used to locate the record in a record set that has the minimum, or lowest, value in a set of values. The PostgreSQL MIN function is an aggregate function used to calculate a single result value from a set of input values. Passing a column to the MIN function in the SELECT statement will locate the minimum column value in a table. This can be a number, string or any like data type. Used in conjunction with the GROUP BY clause, the PostgreSQL MIN function locates the records with the minimum value for each name.

Prerequisites

The following software must be properly installed and configured on the local system to use the Postgres MIN function on an ObjectRocket instance. The software can be downloaded here: PostgreSQL 11

  • An instance of Postgres for an ObjectRocket account must be created via the Mission Control panel, shown here:

PostgreSQL MIN function Statement

The PostgreSQL MIN function is one of the PostgreSQL aggregate functions and, as the name implies, returns the minimum value in a set of values. Following is the basic form of the MIN function statement:

1
2
SELECT MIN(COLUMN)
FROM <table_name>;

A breakdown of the statement follows:

  • First, the SELECT statement is followed by the MIN function that is in turn followed by the name of the column. Note that the column data type can be of any comparable type, string or numerical value.

  • Next, the FROM clause is followed by the table name.

Connecting to a PostgreSQL instance on ObjectRocket

Before being able to perform the MIN function, a connection must first be established to the PostgreSQL instance on ObjectRocket using one of the following two options:

OPTION 1

The first connection option is performed via the psql utility that is included with the PostgreSQL software installation:

1
2
3
4
5
Server [localhost]: ingress.w98sujpz.launchpad.objectrocket.cloud
DATABASE [postgres]: <your_database_name>
Port [5432]: 4149
Username [postgres]: pguser
Password FOR USER orkb: <your_password>

OPTION 2

The second connection option is preformed via the regular Windows terminal:

1
psql -h ingress.w98sujpz.launchpad.objectrocket.cloud -U pguser -d postgres -p 4149

Sample Data Set

Following is the sample data set that will be used in the practice examples in this tutorial:

1
2
3
4
5
6
7
8
9
10
11
12
13
 id |            position            | yearly_salary
----+--------------------------------+---------------
  1 | IT Support                     |         54435
  2 | Technical Support              |         47462
  3 | Systems Administrator          |         83636
  4 | Help Desk Analyst              |         48648
  5 | Desktop Support Technician     |         54545
  6 | IT Technician                  |         80713
  7 | Network Administrator          |         70270
  8 | Field Technician               |         42312
  9 | IT Analyst                     |         79647
 10 | Information Technology Manager |        100071
(10 rows)

Postgres MIN function Example

This first example obtains the minimum salary of IT professionals in the it_salary table by executing the following Postgres MIN function statement:

1
2
3
4
5
sandbox=> SELECT MIN (yearly_salary) FROM it_salary;
  MIN
-------
 42312
(1 ROW)

Notice that the above statement returns the minimum yearly salary of 41312.

Postgres MIN Function with GROUP BY Example

This second example will use the MIN function in conjunction with the GROUP BY clause to provide a more targeted result:

1
2
3
4
5
6
7
8
9
SELECT
    POSITION,
    MIN (yearly_salary)
FROM
    it_salary
GROUP BY
    POSITION
ORDER BY
    POSITION;

The result should resemble the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
            position            |  min
--------------------------------+--------
 Desktop Support Technician     |  54545
 Field Technician               |  42312
 Help Desk Analyst              |  48648
 Information Technology Manager | 100071
 IT Analyst                     |  79647
 IT Support                     |  54435
 IT Technician                  |  80713
 Network Administrator          |  70270
 Systems Administrator          |  83636
 Technical Support              |  47462
(10 rows)

Notice in the above example that combining the Postgres MIN function with other Postgres clauses provides a more comprehensive result.

Conclusion

This tutorial explained how to use the Postgres MIN function on an ObjectRocket instance. The tutorial first covered the needed software and provided a link to obtain the Postgres program. The article then explained the PostgreSQL MIN function statement and provided a breakdown of the command structure. The tutorial then gave instructions for two options for connecting to a PostgreSQL instance on ObjectRocket. The article then provided a sample data set for the examples used in this tutorial and then gave two examples using the Postgres MIN function and MIN function with GROUP BY clause.

Bear in mind that the column data type can be of any comparable type, string or numerical value and that the SELECT statement must be followed by the MIN function that in turn must be followed by the name of the column. Also remember that executing the MIN function in conjunction with the GROUP BY clause will provide more comprehensive results when using the Postgres MIN function on an ObjectRocket instance.

Pilot the ObjectRocket Platform Free!

Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.

Get Started

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.