INSERT INTO
Adds rows to the table. If the target table already exists and is not sorted, the operation INSERT INTO
adds rows at the end of the table. For a sorted table, YQL tries to preserve sorting by starting a sorted merge.
Search for the table by name in the database specified by the USE operator.
INSERT INTO
lets you perform the following operations:
-
Adding constant values using
VALUES
.INSERT INTO my_table (Key1, Key2, Value1, Value2) VALUES (345987,'ydb', 'Apple region', 1414); COMMIT;
INSERT INTO my_table (key, value) VALUES ("foo", 1), ("bar", 2);
-
Saving the
SELECT
result.INSERT INTO my_table SELECT Key AS Key1, "Empty" AS Key2, Value AS Value1 FROM my_table1;
Write operation can be performed with one or more modifiers. The modifier is specified after the WITH
keyword after the table name: INSERT INTO ... WITH SOME_HINT
.
If the modifier has a value, it's specified after the =
sign: INSERT INTO ... WITH SOME_HINT=value
.
If you need to specify multiple modifiers, they must be enclosed in parentheses: INSERT INTO ... WITH (SOME_HINT1=value, SOME_HINT2, SOME_HINT3=value)
.
To clear existing data from the table before the write operation, just add a modifier: INSERT INTO ... WITH TRUNCATE
.
Examples:
INSERT INTO my_table WITH TRUNCATE
SELECT key FROM my_table_source;
The full list of supported write modifiers:
TRUNCATE
to clear existing data from the table.COMPRESSION_CODEC=codec_name
to write data with the specified compression codec. Takes priority over theyt.PublishedCompressionCodec
pragma.
ERASURE_CODEC=erasure_name
to write data with the specified erasure codec. Takes priority over theyt.PublishedErasureCodec
pragma.
Examples:
INSERT INTO my_table WITH (TRUNCATE, EXPIRATION="15m")
SELECT key FROM my_table_source;
INSERT INTO my_table WITH USER_ATTRS="{attr1=value1; attr2=value2;}"
SELECT key FROM my_table_source;