
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()
123SepalLengthCm123SepalWidthCm123PetalLengthCm123PetalWidthCmAbcSpecies1 3.3 4.5 5.6 7.8 Iris-setosa 2 3.3 4.5 5.6 7.8 Iris-setosa 3 3.3 4.5 5.6 7.8 Iris-setosa 4 3.3 4.5 5.6 7.8 Iris-setosa 5 3.3 4.5 5.6 7.8 Iris-setosa 6 3.3 4.5 5.6 7.8 Iris-setosa 7 3.3 4.5 5.6 7.8 Iris-setosa 8 3.3 4.5 5.6 7.8 Iris-setosa 9 3.3 4.5 5.6 7.8 Iris-setosa 10 3.3 4.5 5.6 7.8 Iris-setosa 11 3.3 4.5 5.6 7.8 Iris-setosa 12 3.3 4.5 5.6 7.8 Iris-setosa 13 3.3 4.5 5.6 7.8 Iris-setosa 14 3.3 4.5 5.6 7.8 Iris-setosa 15 3.3 4.5 5.6 7.8 Iris-setosa 16 3.3 4.5 5.6 7.8 Iris-setosa 17 3.3 4.5 5.6 7.8 Iris-setosa 18 3.3 4.5 5.6 7.8 Iris-setosa 19 3.3 4.5 5.6 7.8 Iris-setosa 20 3.3 4.5 5.6 7.8 Iris-setosa 21 3.3 4.5 5.6 7.8 Iris-setosa 22 3.3 4.5 5.6 7.8 Iris-setosa 23 3.3 4.5 5.6 7.8 Iris-setosa 24 3.3 4.5 5.6 7.8 Iris-setosa 25 3.3 4.5 5.6 7.8 Iris-setosa 26 3.3 4.5 5.6 7.8 Iris-setosa 27 4.3 3.0 1.1 0.1 Iris-setosa 28 4.3 4.7 9.6 1.8 Iris-virginica 29 4.3 4.7 9.6 1.8 Iris-virginica 30 4.3 4.7 9.6 1.8 Iris-virginica 31 4.3 4.7 9.6 1.8 Iris-virginica 32 4.3 4.7 9.6 1.8 Iris-virginica 33 4.3 4.7 9.6 1.8 Iris-virginica 34 4.3 4.7 9.6 1.8 Iris-virginica 35 4.3 4.7 9.6 1.8 Iris-virginica 36 4.3 4.7 9.6 1.8 Iris-virginica 37 4.3 4.7 9.6 1.8 Iris-virginica 38 4.3 4.7 9.6 1.8 Iris-virginica 39 4.3 4.7 9.6 1.8 Iris-virginica 40 4.3 4.7 9.6 1.8 Iris-virginica 41 4.3 4.7 9.6 1.8 Iris-virginica 42 4.3 4.7 9.6 1.8 Iris-virginica 43 4.3 4.7 9.6 1.8 Iris-virginica 44 4.3 4.7 9.6 1.8 Iris-virginica 45 4.3 4.7 9.6 1.8 Iris-virginica 46 4.3 4.7 9.6 1.8 Iris-virginica 47 4.3 4.7 9.6 1.8 Iris-virginica 48 4.3 4.7 9.6 1.8 Iris-virginica 49 4.3 4.7 9.6 1.8 Iris-virginica 50 4.3 4.7 9.6 1.8 Iris-virginica 51 4.3 4.7 9.6 1.8 Iris-virginica 52 4.3 4.7 9.6 1.8 Iris-virginica 53 4.3 4.7 9.6 1.8 Iris-virginica 54 4.4 2.9 1.4 0.2 Iris-setosa 55 4.4 3.0 1.3 0.2 Iris-setosa 56 4.4 3.2 1.3 0.2 Iris-setosa 57 4.5 2.3 1.3 0.3 Iris-setosa 58 4.6 3.1 1.5 0.2 Iris-setosa 59 4.6 3.2 1.4 0.2 Iris-setosa 60 4.6 3.4 1.4 0.3 Iris-setosa 61 4.6 3.6 1.0 0.2 Iris-setosa 62 4.7 3.2 1.3 0.2 Iris-setosa 63 4.7 3.2 1.6 0.2 Iris-setosa 64 4.8 3.0 1.4 0.1 Iris-setosa 65 4.8 3.0 1.4 0.3 Iris-setosa 66 4.8 3.1 1.6 0.2 Iris-setosa 67 4.8 3.4 1.6 0.2 Iris-setosa 68 4.8 3.4 1.9 0.2 Iris-setosa 69 4.9 2.4 3.3 1.0 Iris-versicolor 70 4.9 2.5 4.5 1.7 Iris-virginica 71 4.9 3.0 1.4 0.2 Iris-setosa 72 4.9 3.1 1.5 0.1 Iris-setosa 73 4.9 3.1 1.5 0.1 Iris-setosa 74 4.9 3.1 1.5 0.1 Iris-setosa 75 5.0 2.0 3.5 1.0 Iris-versicolor 76 5.0 2.3 3.3 1.0 Iris-versicolor 77 5.0 3.0 1.6 0.2 Iris-setosa 78 5.0 3.2 1.2 0.2 Iris-setosa 79 5.0 3.3 1.4 0.2 Iris-setosa 80 5.0 3.4 1.5 0.2 Iris-setosa 81 5.0 3.4 1.6 0.4 Iris-setosa 82 5.0 3.5 1.3 0.3 Iris-setosa 83 5.0 3.5 1.6 0.6 Iris-setosa 84 5.0 3.6 1.4 0.2 Iris-setosa 85 5.1 2.5 3.0 1.1 Iris-versicolor 86 5.1 3.3 1.7 0.5 Iris-setosa 87 5.1 3.4 1.5 0.2 Iris-setosa 88 5.1 3.5 1.4 0.2 Iris-setosa 89 5.1 3.5 1.4 0.3 Iris-setosa 90 5.1 3.7 1.5 0.4 Iris-setosa 91 5.1 3.8 1.5 0.3 Iris-setosa 92 5.1 3.8 1.6 0.2 Iris-setosa 93 5.1 3.8 1.9 0.4 Iris-setosa 94 5.2 2.7 3.9 1.4 Iris-versicolor 95 5.2 3.4 1.4 0.2 Iris-setosa 96 5.2 3.5 1.5 0.2 Iris-setosa 97 5.2 4.1 1.5 0.1 Iris-setosa 98 5.3 3.7 1.5 0.2 Iris-setosa 99 5.4 3.0 4.5 1.5 Iris-versicolor 100 5.4 3.4 1.5 0.4 Iris-setosa Rows: 1-100 | Columns: 5Note
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 theiris
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
toFalse
for multiple inserts.See also
read_csv()
: Ingests a CSV file using flex tables.read_json()
: Ingests a JSON file using flex tables.