forked from baldimario/cq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_dml.sql
More file actions
53 lines (40 loc) · 1.46 KB
/
example_dml.sql
File metadata and controls
53 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- Example: Data Manipulation Language (DML) operations
-- Shows how to INSERT, UPDATE, and DELETE data in CSV files
/*
* WARNING: These operations modify CSV files directly!
* Make backups before running DML operations on important data.
*/
-- ===== INSERT EXAMPLES =====
-- Insert with all columns specified
-- INSERT INTO './data/users.csv' (id, name, age, role, height, active, email, city)
-- VALUES (100, 'Mario', 35, 'developer', 180.0, 1, 'mario@example.com', 'Rome');
-- Insert with values only (must match column order)
-- INSERT INTO './data/users.csv'
-- VALUES (101, 'Luigi', 32, 'developer', 175.5, 1, 'luigi@example.com', 'Milan');
-- ===== UPDATE EXAMPLES =====
-- Update single column
-- UPDATE './data/users.csv'
-- SET active = 0
-- WHERE age < 18;
-- Update multiple columns with condition
-- UPDATE './data/users.csv'
-- SET role = 'senior', active = 1
-- WHERE age > 40 AND role = 'user';
-- Update all rows (use with caution!)
-- UPDATE './data/users.csv'
-- SET active = 1;
-- ===== DELETE EXAMPLES =====
-- Delete with simple condition
-- DELETE FROM './data/users.csv'
-- WHERE active = 0;
-- Delete with complex condition
-- DELETE FROM './data/users.csv'
-- WHERE age < 18 OR role = 'guest';
-- Note: DELETE always requires a WHERE clause for safety
-- This prevents accidentally deleting all data
/*
* To run these examples:
* 1. Uncomment the desired operation
* 2. Run: cq -f assets/example_dml.sql
* 3. Verify changes in the CSV file
*/