diff options
author | Andreas Fankhauser hiddenalpha.ch | 2024-09-28 23:45:09 +0200 |
---|---|---|
committer | Andreas Fankhauser hiddenalpha.ch | 2024-09-28 23:45:09 +0200 |
commit | 282de8158508f260fe1ea542492616049f672ac7 (patch) | |
tree | 641876b6b8d237cce12c42db281dd68d24dc312a | |
parent | c4684f64e8c5a6462c3a2cc8c00c495200cf6a83 (diff) | |
download | UnspecifiedGarbage-282de8158508f260fe1ea542492616049f672ac7.zip UnspecifiedGarbage-282de8158508f260fe1ea542492616049f672ac7.tar.gz |
Add how to conditionally insert in sqlite query
-rw-r--r-- | doc/note/sqlite/sqlite.txt | 8 |
1 files changed, 8 insertions, 0 deletions
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) |