Thursday , April 25 2024

Select Into In PostgreSQL

In today’s article, we will cover Using Select Into in PostgreSQL. I will use the pagila database for this.

Let’s get to know the subject better with a few examples:

First, we switch to the database as follows.

If you get the message as above, it means you are connected to the database.

If you are connected on pgadmin, you can right-click on the tables under the pagila database, type query tools from the menu that opens, and view the commands below.

You can request the tables in the pagila database with the \dt+ command.

Let’s list those in the California region in the Address column and see how many people there are.

As a result of the table, we see that there are 9 records and let’s create them in a different table called California with the SELECT INTO command.

As a result of the above command, we see that 9 records are affected as follows.

Let’s see our table by listing it with the \dt column.

Our table has been created, let’s see the data with the select clause.

The same operations are valid on the temp table, but the temp table is temporary.

You can transfer your table to temp as follows.

Let’s list our tables and see if our Temp table is created.

We can see that our california table is created under the pg_temp_4 schema.

You can use the select into statement when the table is not created and you want to create only certain columns or all columns and transfer them to the new table.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories