User Tools

Site Tools


newdevs:code:import_csv_into_db

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
newdevs:code:import_csv_into_db [2023/02/27 13:26] – [Importing the Data] tlittlenewdevs:code:import_csv_into_db [2023/02/27 13:31] (current) – [Finessing the Data Prior to Import] tlittle
Line 7: Line 7:
 **Notes:** **Notes:**
   * If the table you're wanting to insert into uses an org, you'll want to edit your CSV file first to use the org IDs from Concerto.   * If the table you're wanting to insert into uses an org, you'll want to edit your CSV file first to use the org IDs from Concerto.
-  * Don't include the column for ID from your production data--delete that.+  * Don't include the column for ID from your production data.
   * If there are duplicate key constraints, check for those in your CSV *first* before you create your tables. For example, acq.provider has a duplicate key value unique constraint of "provider_name_once_per_owner". If you add a column in your CSV for dupe checking, you can use a formula to count how many times it appears and thus find dupes.   * If there are duplicate key constraints, check for those in your CSV *first* before you create your tables. For example, acq.provider has a duplicate key value unique constraint of "provider_name_once_per_owner". If you add a column in your CSV for dupe checking, you can use a formula to count how many times it appears and thus find dupes.
  
Line 14: Line 14:
 This assumes that Column A is the no-dupe column (name, in this case) and Column B is the org. So basically, count the number of times that the name in A2 appears with the same org that's in B2. Then if we fill that down the entire column, if you get anything above a 1 you have a dupe that you can filter for and remove. This assumes that Column A is the no-dupe column (name, in this case) and Column B is the org. So basically, count the number of times that the name in A2 appears with the same org that's in B2. Then if we fill that down the entire column, if you get anything above a 1 you have a dupe that you can filter for and remove.
  
 +**TIP:** If you're not sure if your table includes a uniqueness constraint, here's a grep of the Evergreen repo for the word "CONSTRAINT" which can point you toward where you might encounter a uniqueness constraint on the table you're working on: https://git.evergreen-ils.org/?p=Evergreen.git&a=search&h=HEAD&st=grep&s=CONSTRAINT
 ===== Importing the Data ===== ===== Importing the Data =====
  
Line 39: Line 40:
 <code>copy tlittle.acqprolist from '/home/tlittle/pines_acqprolist.csv' csv header;</code> <code>copy tlittle.acqprolist from '/home/tlittle/pines_acqprolist.csv' csv header;</code>
  
-Then if you do a select * from tlittle.acqprolist you'll see it's now populated with the data from our CSV file.+Then if you do a **select * from tlittle.acqprolist** you'll see it's now populated with the data from our CSV file.
  
 5. To get that data into our Evergreen table, we need to copy it over. 5. To get that data into our Evergreen table, we need to copy it over.
Line 59: Line 60:
 So the second half is the SELECT--select all these from tlittle.acqprolist--which we then INSERT with the first portion. So the second half is the SELECT--select all these from tlittle.acqprolist--which we then INSERT with the first portion.
  
-If it's successful, you'll get the INSERT 0 [NUMBER OF ROWS] message. You can then do a select * from acq.provider to see all your new data.+If it's successful, you'll get the INSERT 0 [NUMBER OF ROWS] message. You can then do a **select * from [YOUR TABLE]** to see all your new data.
newdevs/code/import_csv_into_db.1677522380.txt.gz · Last modified: 2023/02/27 13:26 by tlittle

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

© 2008-2022 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a U.S. 501(c)3 non-profit organization.