Home Applications csv2table

csv2table

This application is not supported by InterSystems Corporation. Please be notified that you use it at your own risk.
4.5
1 reviews
0
Awards
201
Views
11
IPM installs
0
1
Details
Releases
Reviews
Issues
Pull requests
Articles
Dependencies
Example on how to import CSV to any existing table

What's new in this version

Added a description to the ZPM package

import csv and update with SQL

This is an example on how to import CSV data to any table using SQL.

The related article is on Developer Community

Prerequisites

Make sure you have git and Docker desktop installed.

Installation with Docker

Clone/git pull the repo into any local directory

$ git clone https://github.com/intersystems-community/objectscript-docker-template.git

Open the terminal in a cloned folder and run the container with InterSystems IRIS:

$ docker-compose up -d

Installation with ZPM

Open IRIS terminal and run

USER>zpm "install import-csv-update-sql"

How to Use it

In this example we use Countries dataset and GNP dataset to change the GNP column in Countries dataset.
we will import GNP CSV with csvgen and then run the SQL update query that will change the data in dc_data.Country class/table for the GNP values from GNP class generated from CSV.
And then we delete GNP class.

Open IRIS terminal:

$ docker-compose exec iris iris session iris
USER>
  1. Import dataset
  2. Show the initial value
USER>zw ##class(evshvarov.csv.sqlupdate).ImportDataset()
...
[dataset-countries]     Activate SUCCESS
USER>zw ##class(evshvarov.csv.sqlupdate).AddGNP()
"SQLCODE=0"
USER>zw ##class(evshvarov.csv.sqlupdate).ShowGNP()
Country gnp=
1
  1. Import CSV with the demanded data:
USER>zw ##class(evshvarov.csv.sqlupdate).ImportCSV()
Class name: dc.data.GNP
Header: "CountryName" VARCHAR(250),"CountryCode" VARCHAR(250), . . .
Records imported: 2661
  1. Change the data:
USER>zw ##class(evshvarov.csv.sqlupdate).UpdateGNP()
Changes to GNP are made from dc.data.GNP
1
USER>zw ##class(evshvarov.csv.sqlupdate).ShowGNP()
Country Armenia gnp=12424.5488
1
  1. Delete GNP table:
USER>zw ##class(evshvarov.csv.sqlupdate).DropGNP()
dc.data.DNP class is deleted.
1

Or you can run all the process with RunAll() method:

zw ##class(evshvarov.csv.sqlupdate).RunAll()
Read more
Made with
Install
zpm install import-csv-update-sql download archive
Version
1.0.129 Sep, 2021
ObjectScript quality test
Category
Technology Example
Works with
InterSystems IRIS
First published
21 Sep, 2021
Last checked by moderator
27 Jun, 2023Works