Step 1) Create this new SQL table : CREATE TABLE student_names (This is a dummy example but it’ll do the job for now.) Say we want to create a table where we want to store only the names from our test_results table. csv file into our SQL table.Īwesome! Method #3: Insert the output of another SQL query into your SQL tableĭo you want to store the output of your SQL query? Not a problem… Maybe you want to save your daily KPIs that are calculated from SQL tables - or you want to have the cleaned version of a data set next to the original. And finally: if you are uncomfortable with these command-line steps, read the first few articles from my Command Line for Data Analysts article series.Īnd boom, the data is inserted from a.Again, we found out the location by using the pwd command. The '/home/dataguy/test_results.csv' is the location and the name of the file, together.If you follow the video that I linked in the previous point, you will be able to run the same COPY statement from pgadmin or SQL Workbench. Why we didn’t do the COPY command in our SQL manager tool? Same reason: if you don’t have SUPERUSER privileges, you can’t run the COPY command from an SQL manager tool - only from the command line.If you are here from one of my online courses, probably we have already fixed this issue in the course.) (In this video starting at 2:55 I show how to give SUPERUSER privileges to your SQL user. Typing \COPY instead is the simplest workaround - but the best solution would be to give yourself SUPERUSER privileges then use the original COPY command. I typed \COPY and not just COPY because my SQL user doesn’t have SUPERUSER privileges, so technically I could not use the COPY command (this is an SQL thing).(Note: At this point assume you know how to do it – if not: this way please.) STEP 1) First, you have to open your Terminal window and connect to your data server. csv file, you can just skip STEP #1, #2, and #3. Note: in this example, I’ll help you to create a dummy. Let’s go through the whole process with an example. So in this case ' ' means that the delimiter would be a space.Įxample for COPY (insert. And eventually, you have to specify the field separator in your original file by typing DELIMITER and the field separator itself between apostrophes.…specify the name and the location of the file that you want to COPY the data from. FROM is another SQL keyword after that you’ll….So just get over it and simply learn this way.) (This is a bit counter-intuitive in the syntax… But we know that SQL is not the most “coder-friendly” tool syntax-wise.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |