This is part 2 in continuation from the post Your Personal Database.
Now that we have a personal SQL database set up in DataGrip, let’s import our first data table. Note that this is for a personal database set up on a local computer. Not a shared database connected to an online server (which is what most companies or organizations would use).
Here’s how to import a table:
Step 1: Find the “public > tables” folder to which tables will get saved.
Starting with a fresh PostgreSQL database set up, this was located in postgres > public > tables.
If you do not see a “tables” folder, then use “public”. The tables folder will get automatically created upon importing your first table.
Do not use “Database Objects” or “Server Objects”.
Step 2: Right click on “public” or “public > tables” folder > Import/Export > Import Data from File(s).
Step 3: Select the data file to be imported as a table, then ‘OK’.
Make sure the file is closed. For example, do not have the .xlsx or .csv open in Excel on your computer, or else you will get an error.
Note how many rows of data the original file has (will use for validation in step 5).
Step 4: Set import format settings and set up SQL table.
Select the file format (top left corner).
Check “First row is header” if it applies (this is not checked by default).Z
Set the SQL table name (top right).
Review the header names (middle right). Double click on each and rename column names to lowercase with underscores replacing spaces in order to avoid using quotes ” to reference column names in SQL queries. You don’t need to redo this step when importing new data into this table in the future (but you can go back and edit).
Click “Import”.
Step 5: Validate that all data rows were imported.
A popup will appears in the bottom right corner showing how many rows were imported, and if any, how many errors were written.
Check #1: The number of rows imported should match what you expect from the original data file. For example, my data has 64 rows in the original CSV – (1) header row, and (63) data rows. So I expect 63 rows to be imported to the table.
If there were any errors, they were not imported into the data table. Investigate, fix, and re-import.
Step 6: Verify that the data looks right.
The newly imported table now appears under the “tables” folder on the top left corner.
Double click on this to view the table within DataGrip. Check that the data looks correct and as you expect.
Issues might include:
– Dates are blank or missing values (check that they have the right data type in Step 4, ie Date or Text)
– Too many rows: Old data on the table was not deleted, and newly imported data was appended on instead of replacing the old data
Step 7: Test it out!
See if it works!
SELECT * FROM new_table;
Happy SQL querying!