In today’s article we will cover the topic of Import Dat File Into PostgreSQL.
Sometimes we need to import/export some tables in PostgreSQL. In this article, we will import the .dat file on PostgreSQL into the table. While doing this, we will do it through pgadmin, which is the simplest and easiest way.
First of all, we need to create a table that will match the columns in our file with the “.dat” extension to import.
1 2 3 4 5 6 |
CREATE TABLE public.film_category ( film_id smallint NOT NULL, category_id smallint NOT NULL, last_update timestamp without time zone NOT NULL DEFAULT now() ) |
We created our table as above.
NOTE: If the table is not created, the import\export command will not work.
After right-clicking on the table, we click on the import\export button.
In the Filename section, we go to the location of our .dat file and select our .dat file.
After selecting our .dat file, we come to the next section in the Format window and select the “binary” part.
After selecting Filename and Format in the above figure, pressing the “ok” key, we will transfer our .dat file to the table by running the copy command below on the back side.
As can be seen above, our 1000 records have been successfully transferred into the table.