insert_into

In [ ]:
insert_into(table_name: str,
            data: list,
            schema: str = "",
            column_names: list = [],
            copy: bool = True,
            genSQL: bool = False,)

Inserts the dataset into an existing Vertica table.

Parameters

Name Type Optional Description
table_name
str
Name of the table to insert into.
data
list
The data to ingest.
schema
str
Schema name.
column_names
list
Name of the column(s) to insert into.
copy
bool
If set to True, the batch insert is converted to a COPY statement with prepared statements. Otherwise, the INSERTs are performed sequentially.
genSQL
bool
If set to True, the SQL code that would be used to insert the data is generated, but not executed.

Returns

int : The number of rows ingested.

Example

In [28]:
from verticapy.datasets import load_iris
iris = load_iris()
iris
Out[28]:
123
SepalLengthCm
Numeric(5,2)
123
SepalWidthCm
Numeric(5,2)
123
PetalLengthCm
Numeric(5,2)
123
PetalWidthCm
Numeric(5,2)
Abc
Species
Varchar(30)
14.33.01.10.1Iris-setosa
24.42.91.40.2Iris-setosa
34.43.01.30.2Iris-setosa
44.43.21.30.2Iris-setosa
54.52.31.30.3Iris-setosa
64.63.11.50.2Iris-setosa
74.63.21.40.2Iris-setosa
84.63.41.40.3Iris-setosa
94.63.61.00.2Iris-setosa
104.73.21.30.2Iris-setosa
114.73.21.60.2Iris-setosa
124.83.01.40.1Iris-setosa
134.83.01.40.3Iris-setosa
144.83.11.60.2Iris-setosa
154.83.41.60.2Iris-setosa
164.83.41.90.2Iris-setosa
174.92.43.31.0Iris-versicolor
184.92.54.51.7Iris-virginica
194.93.01.40.2Iris-setosa
204.93.11.50.1Iris-setosa
214.93.11.50.1Iris-setosa
224.93.11.50.1Iris-setosa
235.02.03.51.0Iris-versicolor
245.02.33.31.0Iris-versicolor
255.03.01.60.2Iris-setosa
265.03.21.20.2Iris-setosa
275.03.31.40.2Iris-setosa
285.03.41.50.2Iris-setosa
295.03.41.60.4Iris-setosa
305.03.51.30.3Iris-setosa
315.03.51.60.6Iris-setosa
325.03.61.40.2Iris-setosa
335.12.53.01.1Iris-versicolor
345.13.31.70.5Iris-setosa
355.13.41.50.2Iris-setosa
365.13.51.40.2Iris-setosa
375.13.51.40.3Iris-setosa
385.13.71.50.4Iris-setosa
395.13.81.50.3Iris-setosa
405.13.81.60.2Iris-setosa
415.13.81.90.4Iris-setosa
425.22.73.91.4Iris-versicolor
435.23.41.40.2Iris-setosa
445.23.51.50.2Iris-setosa
455.24.11.50.1Iris-setosa
465.33.71.50.2Iris-setosa
475.43.04.51.5Iris-versicolor
485.43.41.50.4Iris-setosa
495.43.41.70.2Iris-setosa
505.43.71.50.2Iris-setosa
515.43.91.30.4Iris-setosa
525.43.91.70.4Iris-setosa
535.52.34.01.3Iris-versicolor
545.52.43.71.0Iris-versicolor
555.52.43.81.1Iris-versicolor
565.52.54.01.3Iris-versicolor
575.52.64.41.2Iris-versicolor
585.53.51.30.2Iris-setosa
595.54.21.40.2Iris-setosa
605.62.53.91.1Iris-versicolor
615.62.74.21.3Iris-versicolor
625.62.84.92.0Iris-virginica
635.62.93.61.3Iris-versicolor
645.63.04.11.3Iris-versicolor
655.63.04.51.5Iris-versicolor
665.72.55.02.0Iris-virginica
675.72.63.51.0Iris-versicolor
685.72.84.11.3Iris-versicolor
695.72.84.51.3Iris-versicolor
705.72.94.21.3Iris-versicolor
715.73.04.21.2Iris-versicolor
725.73.81.70.3Iris-setosa
735.74.41.50.4Iris-setosa
745.82.64.01.2Iris-versicolor
755.82.73.91.2Iris-versicolor
765.82.74.11.0Iris-versicolor
775.82.75.11.9Iris-virginica
785.82.75.11.9Iris-virginica
795.82.85.12.4Iris-virginica
805.84.01.20.2Iris-setosa
815.93.04.21.5Iris-versicolor
825.93.05.11.8Iris-virginica
835.93.24.81.8Iris-versicolor
846.02.24.01.0Iris-versicolor
856.02.25.01.5Iris-virginica
866.02.75.11.6Iris-versicolor
876.02.94.51.5Iris-versicolor
886.03.04.81.8Iris-virginica
896.03.44.51.6Iris-versicolor
906.12.65.61.4Iris-virginica
916.12.84.01.3Iris-versicolor
926.12.84.71.2Iris-versicolor
936.12.94.71.4Iris-versicolor
946.13.04.61.4Iris-versicolor
956.13.04.91.8Iris-virginica
966.22.24.51.5Iris-versicolor
976.22.84.81.8Iris-virginica
986.22.94.31.3Iris-versicolor
996.23.45.42.3Iris-virginica
1006.32.34.41.3Iris-versicolor
Rows: 1-100 | Columns: 5
In [9]:
from verticapy.utilities import insert_into
# copy left as default (True): one copy
insert_into(table_name = "iris",
            schema = "public",
            data = [[3.3, 4.5, 5.6, 7.8, "Iris-setosa"], 
                    [4.3, 4.7, 9.6, 1.8, "Iris-virginica"]],)
Out[9]:
2
In [10]:
# copy set to False: multiple inserts
insert_into(table_name = "iris",
            schema = "public",
            data = [[3.3, 4.5, 5.6, 7.8, "Iris-setosa"], 
                    [4.3, 4.7, 9.6, 1.8, "Iris-virginica"]],
            copy=False,)
Out[10]:
2
In [11]:
# genSQL set to True: SQL for inserting data is generated, but not executed
# copy set to False: multiple inserts
insert_into(table_name = "iris",
            schema = "public",
            data = [[3.3, 4.5, 5.6, 7.8, "Iris-setosa"], 
                    [4.3, 4.7, 9.6, 1.8, "Iris-virginica"]],
            genSQL=True,)
Out[11]:
['INSERT INTO "public"."iris" ("SepalLengthCm", "SepalWidthCm", "PetalLengthCm", "PetalWidthCm", "Species") VALUES (\'3.3\',\'4.5\',\'5.6\',\'7.8\',\'Iris-setosa\');',
 'INSERT INTO "public"."iris" ("SepalLengthCm", "SepalWidthCm", "PetalLengthCm", "PetalWidthCm", "Species") VALUES (\'4.3\',\'4.7\',\'9.6\',\'1.8\',\'Iris-virginica\');']

See Also

read_csv Ingests a CSV file into the Vertica DB.
read_json Ingests a JSON file into the Vertica DB.