Skip to main content

Importing Data from a Text File

Importing Data from a Text File

To import data into an SQL table within InterSystems IRIS, you must create a table to contain the data first (if one does not already exist). You can do this by defining a persistent class which projects itself as a table or by issuing a CREATE TABLE command.

Once you have created the table which will contain your data, you can import the data using one of the following methods:

  • Issue a LOAD DATA SQL command. This utility can be used to import data either from a file or from a table accessed with JDBC. If the table is empty when loading data, LOAD DATA populates the table with rows from the data source. If the table already contains data, LOAD DATA inserts rows into the table without overwriting any data in the table.

    The following example creates a table and loads data into it using a file stored on a local system, named people.csv:

    >>> CREATE TABLE Sample.Person (
            Name VARCHAR(25),
            Age INT,
            DOB DATE)
    
    >>> LOAD DATA FROM FILE 'C://sampledata/people.csv' INTO Sample.Person
    

    LOAD DATA also provides options for speeding up the loading operation through use of the BULK keyword. Refer to the LOAD DATA reference for a full description of this behavior.

  • If your data is stored in a .csv or .txt file: use the Management Portal’s Data Import wizard. This wizard can insert records into the table from the file, mapping the file’s columns onto existing columns in the table. To do this:

    1. From the Management Portal, select System Explorer, then SQL.

    2. At the top of the main pane, click the Wizards drop-down list, and select Data Import.

    3. On the first page of the wizard:

      • Select the radio button which corresponds to the file system where your file is located: you can choose to import data from your machine’s local file system (My Local machine) or from the instance’s host environment (identified by its host name), in deployments where this is different from the machine’s local file system—when the instance is running within a container, for example.

      • Select Browse, and then use the dialog window to specify the path and name for the .csv or .txt file which contains the data that you would like to import.

      • Optionally: if the file uses a Charset other than the system default, select it from the drop-down list.

      • From the drop-down lists, select the namespace, schema name, and table name for the table into which you would like to import your data.

      Then click Next.

    4. On the second page of the wizard, use the arrow buttons to select the table columns into which you would like to import your data from the list of Available columns. (By default, all of the columns in the table are Selected.) Use the up and down arrows to ensure that the selected columns are listed in same order in which the analogous columns appear in your data file. Then click Next.

    5. On the third page of the wizard:

      • For What delimiter separates your columns?, select the option which identifies the delimiter used to separate columns in your file. If columns are separated by a particular character, use the text box to specify the character.

      • Ensure that the First row contains column headers? checkbox is selected if the first row of your data file contains the file’s column headers. Clear the checkbox if it does not.

      • For String quote, use the drop-down list to select the character which the file uses to indicate the start and end of strings.

      • For Date format, click an option to indicate the format that the file uses for date values.

      • For Time format, click an option to indicate the format that the file uses for time values.

      • For TimeStamp format, click an option to indicate the format that the file uses for Timestamp values.

      • If you do not want the wizard to attempt to validate the data during the import process, select the Disable validation? checkbox. If checked, the wizard specifies %NOCHECK in the restriction parameter of the INSERT command that it issues.

      • Select Defer Index Building with %SortBegin/%SortEnd? if you want the wizard to build indexes after the data has been inserted. When selected, the wizard calls the class's %SortBegin() method prior to inserting the data in the table. This causes the index entries to be written to a temporary location for sorting. They are written to the actual index location when the wizard calls the %SortEnd() method, after all rows have been inserted.

        InterSystems recommends that you do not defer index building if the destination table contains unique indexes, because it prevents InterSystems IRIS from catching violations of the unique constraint during the import process.

      • Optionally: click Preview Data to view some of your file’s contents.

      Then click Next.

    6. Review your entries and click Finish. The wizard starts a background task to perform the import, and displays the Import Result dialog window.

    7. Within the Import Result window, click the link provided to view the background tasks page. From there, you can check the status of the import task and review any errors which may have occurred.

    8. Click Close to close the Import Result window.

FeedbackOpens in a new tab