mirror of
https://github.com/tursodatabase/libsql.git
synced 2024-12-12 15:33:44 +00:00
ad79ef48a2
* add tests * add bench
55 lines
1.2 KiB
Plaintext
55 lines
1.2 KiB
Plaintext
|
|
CREATE TABLE data(x, y, z);
|
|
CREATE VIEW t1 AS SELECT * FROM data;
|
|
CREATE TRIGGER t1_insert INSTEAD OF INSERT ON t1 BEGIN
|
|
INSERT INTO data VALUES(new.x, new.y, new.z);
|
|
END;
|
|
CREATE TRIGGER t1_update INSTEAD OF UPDATE ON t1 BEGIN
|
|
INSERT INTO log VALUES(old.z || '->' || new.z);
|
|
END;
|
|
|
|
CREATE TABLE log(t TEXT);
|
|
|
|
INSERT INTO t1 VALUES(1, 'i', 'one');
|
|
INSERT INTO t1 VALUES(2, 'ii', 'two');
|
|
INSERT INTO t1 VALUES(3, 'iii', 'three');
|
|
INSERT INTO t1 VALUES(4, 'iv', 'four');
|
|
|
|
|
|
WITH input(k, v) AS (
|
|
VALUES(3, 'thirty'), (1, 'ten')
|
|
)
|
|
UPDATE t1 SET z=v FROM input WHERE x=k;
|
|
|
|
|
|
CREATE TABLE x1(a, b, c);
|
|
CREATE TABLE x2(a, b, c);
|
|
|
|
|
|
CREATE TABLE t1(a);
|
|
|
|
|
|
UPDATE t1 SET a = 1 FROM (
|
|
SELECT * FROM t1
|
|
)
|
|
|
|
|
|
UPDATE t1 SET a = 1 FROM (
|
|
SELECT * FROM t1 UNION ALL SELECT * FROM t1
|
|
)
|
|
|
|
|
|
CREATE TABLE t1(a);
|
|
INSERT INTO t1(a) VALUES(11),(22),(33),(44),(55);
|
|
CREATE VIEW t2(b,c) AS SELECT a, COUNT(*) OVER () FROM t1;
|
|
CREATE TABLE t3(x,y);
|
|
CREATE TRIGGER t2r1 INSTEAD OF UPDATE ON t2 BEGIN
|
|
INSERT INTO t3(x,y) VALUES(new.b,new.c);
|
|
END;
|
|
SELECT * FROM t2;
|
|
|
|
|
|
UPDATE t2 SET c=t1.a FROM t1 WHERE t2.b=t1.a;
|
|
SELECT * FROM t3;
|
|
|