Create a Postgres Table on ObjectRocket
If you’re getting started with a Postgres instance on ObjectRocket, one of the first tasks you’ll probably need to do is create a table. Fortunately, the process is a very simple one. In this article, we’ll show you how to create a Postgres table on ObjectRocket, providing detailed instructions for each step of the task.
A few key prerequisites need to be in place before proceeding with this tutorial. First, the following software must be installed and configured:
You must also create an instance of Postgres for your ObjectRocket account. You can do this using ObjectRocket’s Mission Control panel.
Connect Psql to Postgres Server on ObjectRocket
In order to create a database and a corresponding table, we’ll need to connect to our Postgres server instance on ObjectRocket.
The connection details can be found at the “CONNECT” tab on the ObjectRocket Mission Control panel. Here’s how you can locate those details:
- First, click on the VIEW MORE DETAILS button on the lower right corner of the panel.
- Then, select the “CONNECT” tab.
- Finally, we connect to the Postgres server on ObjectRocket using the following command:
psql -h ingress.w98sujpz.launchpad.objectrocket.cloud -p 4149 -U pguser -d PostgreSQL
psqlutility will prompt us for the user password to connect to the server. Once we enter it, we’ll be connected to Postgres.
Creating a Postgres Table
Now that we were able to connect to Postgres, we can turn our attention to the task of creating a table. To create a Postgres table, we use the
CREATE TABLE SQL statement. The basic syntax of this statement is shown below:
CREATE TABLE <tableName> (
columnName TYPE columnConstraint,
In the above statement, we first call the
CREATE TABLE keyword, which instructs the database system to create a new database table. Next, we list the column names and their corresponding data types and column constraints. We can specify multiple columns by separating them with commas.
Creating PostgreSQL Table Example
In this section, we’ll create a PostgreSQL table named
personnel with the following details:
id: PRIMARY KEY NOT NULL
name: VARCHAR(50) NOT NULL
lastname: VARCHAR(50) NOT NULL
Shown below is the
CREATE TABLE statement that we will use to create the
CREATE TABLE personnel(
id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(50) NOT NULL,
lastname VARCHAR(50) NOT NULL,
Note that were able to create multiple columns that were separated by commas.
When we execute the above statement, we’ll see a response like this if no error occurred:
To verify that our table was successfully created, we can use the
\d command in
psql. We should see output that looks like the following:
List of relations
Schema | Name | Type | Owner
public | personnel | table | pguser
public | personnel_id_seq | sequence | pguser
We can see that our
personnel table was created, although this output doesn’t reveal any details about the table. To view the table details and the corresponding columns, we use the
\d followed by the name of the table. The result should look like this:
PostgreSQL=> \d personnel
Column | Type | Collation | Nullable | Default
id | integer | | not null | nextval('personnel_id_seq'::regclass)
name | character varying(50) | | not null |
lastname | character varying(50) | | not null |
age | integer | | |
"personnel_pkey" PRIMARY KEY, btree (id)
We can see that our table was created successfully.
Creating a table is a fundamental task in database administration, so it’s important to know how to complete the process correctly. When you work with a Postgres instance on ObjectRocket, it’s easy to create any tables you need. In this article, we showed you how to create a Postgres table on ObjectRocket and provided step-by-step instructions for the entire process. With this tutorial to guide you, you’ll be ready to create tables on your own Postgres instance.
Pilot the ObjectRocket Platform Free!
Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.Get Started