From 282de8158508f260fe1ea542492616049f672ac7 Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Sat, 28 Sep 2024 23:45:09 +0200 Subject: Add how to conditionally insert in sqlite query --- doc/note/sqlite/sqlite.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/note/sqlite/sqlite.txt b/doc/note/sqlite/sqlite.txt index 3805e07..ddcc0ae 100644 --- a/doc/note/sqlite/sqlite.txt +++ b/doc/note/sqlite/sqlite.txt @@ -26,6 +26,13 @@ csv Example (no headrow): sqlite3 foo.db -bail -cmd '.mode csv' -cmd '.separator ;' -cmd '.import foo.csv FooTable' +## Insert conditional + +INSERT INTO table(id, text) +SELECT 5, 'text to insert' +WHERE NOT EXISTS (SELECT 1 FROM table WHERE id = 5) + + ## Drop Column ALTER TABLE table DROP COLUMN column; @@ -39,4 +46,5 @@ csv Example (no headrow): ## Refs [drop column TODO vote](https://stackoverflow.com/a/66399224/4415884) +[insert if not exists](https://stackoverflow.com/a/19337206/4415884) -- cgit v1.1