Loading...

verticapy.insert_into#

verticapy.insert_into(table_name: str, data: list, schema: str | None = None, column_names: list | None = None, copy: bool = True, genSQL: bool = False) int | str#

Inserts the dataset into an existing Vertica table.

Parameters#

table_name: str

Name of the table to insert into.

data: list

The data to ingest.

schema: str, optional

Schema name.

column_names: list, optional

Name of the column(s) to insert into.

copy: bool, optional

If set to True, the batch insert is converted to a COPY statement with prepared statements. Otherwise, the INSERTs are performed sequentially.

genSQL: bool, optional

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.

Examples#

For this example, we will use the Iris dataset.

import verticapy.datasets as vpd

data = vpd.load_iris()
123
SepalLengthCm
Numeric(7)
123
SepalWidthCm
Numeric(7)
123
PetalLengthCm
Numeric(7)
123
PetalWidthCm
Numeric(7)
Abc
Species
Varchar(30)
13.34.55.67.8Iris-setosa
23.34.55.67.8Iris-setosa
33.34.55.67.8Iris-setosa
43.34.55.67.8Iris-setosa
53.34.55.67.8Iris-setosa
63.34.55.67.8Iris-setosa
73.34.55.67.8Iris-setosa
83.34.55.67.8Iris-setosa
93.34.55.67.8Iris-setosa
103.34.55.67.8Iris-setosa
113.34.55.67.8Iris-setosa
123.34.55.67.8Iris-setosa
133.34.55.67.8Iris-setosa
143.34.55.67.8Iris-setosa
153.34.55.67.8Iris-setosa
163.34.55.67.8Iris-setosa
173.34.55.67.8Iris-setosa
183.34.55.67.8Iris-setosa
193.34.55.67.8Iris-setosa
203.34.55.67.8Iris-setosa
213.34.55.67.8Iris-setosa
223.34.55.67.8Iris-setosa
233.34.55.67.8Iris-setosa
243.34.55.67.8Iris-setosa
253.34.55.67.8Iris-setosa
263.34.55.67.8Iris-setosa
273.34.55.67.8Iris-setosa
283.34.55.67.8Iris-setosa
293.34.55.67.8Iris-setosa
303.34.55.67.8Iris-setosa
313.34.55.67.8Iris-setosa
323.34.55.67.8Iris-setosa
333.34.55.67.8Iris-setosa
343.34.55.67.8Iris-setosa
353.34.55.67.8Iris-setosa
363.34.55.67.8Iris-setosa
373.34.55.67.8Iris-setosa
383.34.55.67.8Iris-setosa
393.34.55.67.8Iris-setosa
403.34.55.67.8Iris-setosa
413.34.55.67.8Iris-setosa
423.34.55.67.8Iris-setosa
434.33.01.10.1Iris-setosa
444.34.79.61.8Iris-virginica
454.34.79.61.8Iris-virginica
464.34.79.61.8Iris-virginica
474.34.79.61.8Iris-virginica
484.34.79.61.8Iris-virginica
494.34.79.61.8Iris-virginica
504.34.79.61.8Iris-virginica
514.34.79.61.8Iris-virginica
524.34.79.61.8Iris-virginica
534.34.79.61.8Iris-virginica
544.34.79.61.8Iris-virginica
554.34.79.61.8Iris-virginica
564.34.79.61.8Iris-virginica
574.34.79.61.8Iris-virginica
584.34.79.61.8Iris-virginica
594.34.79.61.8Iris-virginica
604.34.79.61.8Iris-virginica
614.34.79.61.8Iris-virginica
624.34.79.61.8Iris-virginica
634.34.79.61.8Iris-virginica
644.34.79.61.8Iris-virginica
654.34.79.61.8Iris-virginica
664.34.79.61.8Iris-virginica
674.34.79.61.8Iris-virginica
684.34.79.61.8Iris-virginica
694.34.79.61.8Iris-virginica
704.34.79.61.8Iris-virginica
714.34.79.61.8Iris-virginica
724.34.79.61.8Iris-virginica
734.34.79.61.8Iris-virginica
744.34.79.61.8Iris-virginica
754.34.79.61.8Iris-virginica
764.34.79.61.8Iris-virginica
774.34.79.61.8Iris-virginica
784.34.79.61.8Iris-virginica
794.34.79.61.8Iris-virginica
804.34.79.61.8Iris-virginica
814.34.79.61.8Iris-virginica
824.34.79.61.8Iris-virginica
834.34.79.61.8Iris-virginica
844.34.79.61.8Iris-virginica
854.34.79.61.8Iris-virginica
864.42.91.40.2Iris-setosa
874.43.01.30.2Iris-setosa
884.43.21.30.2Iris-setosa
894.52.31.30.3Iris-setosa
904.63.11.50.2Iris-setosa
914.63.21.40.2Iris-setosa
924.63.41.40.3Iris-setosa
934.63.61.00.2Iris-setosa
944.73.21.30.2Iris-setosa
954.73.21.60.2Iris-setosa
964.83.01.40.1Iris-setosa
974.83.01.40.3Iris-setosa
984.83.11.60.2Iris-setosa
994.83.41.60.2Iris-setosa
1004.83.41.90.2Iris-setosa
Rows: 1-100 | Columns: 5

Note

VerticaPy offers a wide range of sample datasets that are ideal for training and testing purposes. You can explore the full list of available datasets in the Datasets, which provides detailed information on each dataset and how to use them effectively. These datasets are invaluable resources for honing your data analysis and machine learning skills within the VerticaPy environment.

We import the insert_into function and insert different element to the iris table.

from verticapy.sql import insert_into

You can insert all the elements at once with a single COPY statement by using the following command.

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[2]: 2

If you want to use multiple inserts to avoid a general failure and insert what you can, use the following approach.

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[3]: 2

If you want to examine the generated SQL without executing it, use the following command.

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[4]: 
['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\')']

Note

Set copy to False for multiple inserts.

See also

read_csv() : Ingests a CSV file using flex tables.
read_json() : Ingests a JSON file using flex tables.