1. Corresponding excel data to pg database table
There is a table in the database that looks like this:
where user_id needs to be saved as GUID
We need to import the data from excel. Then we must make the field name in the table and the field name of excel the same . If it is a field without content, you can choose not to create it in excel.
excel as shown below:
2. Save excel as a csv file whose character encoding is UTF-8
If prompted, select "Yes"
If you are not allowed to choose the encoding when saving, then we can find the csv file we saved, right-click the saved file, open it with Notepad, and then select the encoding when saving the file as
Then you can start importing
Three, excel import database
First, create a temporary table with the same fields as in excel, as follows:
Right-click the temporary table and select Import/Export
Select Import, and choose the file we saved
Then click OK, and a prompt appears, indicating that the import was successful.
Fourth, insert the contents of the temporary table into the table we need
It can be seen that there are two fields in our temporary table and t_user table, which are user_id and remark, where user_id is guid
We need to query a view that is exactly the same as the t_user table
First create the guid extension and execute:
create extension "uuid-ossp"
Execute the following statement after success:
select uuid_generate_v4() user_id,user_name, age, gender,null remark from t_table
Got the following result:
This is exactly the same as the t_user table. Then we execute
indicate success
Look at the t_user table again:
You can see that it has been inserted successfully