@@ -354,6 +354,104 @@ The object may contain **warning_db_failure** if the database fails partway thro
354
354
355
355
On failure, an error is returned.
356
356
357
+ EXAMPLES
358
+ --------
359
+ Here are some example using lightning-cli. Note that you may need to
360
+ use ` -o ` if you use queries which contain ` = ` (which make
361
+ lightning-cli(1) default to keyword style):
362
+
363
+ A simple peer selection query:
364
+
365
+ ```
366
+ $ lightning-cli sql "SELECT id FROM peers"
367
+ {
368
+ "rows": [
369
+ [
370
+ "02ba9965e3db660385bd1dd2c09dd032e0f2179a94fc5db8917b60adf0b363da00"
371
+ ]
372
+ ]
373
+ }
374
+ ```
375
+
376
+ A statement containing using ` = ` needs ` -o ` :
377
+
378
+ ```
379
+ $ lightning-cli sql -o "SELECT node_id,last_timestamp FROM nodes WHERE last_timestamp>=1669578892"
380
+ {
381
+ "rows": [
382
+ [
383
+ "02ba9965e3db660385bd1dd2c09dd032e0f2179a94fc5db8917b60adf0b363da00",
384
+ 1669601603
385
+ ]
386
+ ]
387
+ }
388
+ ```
389
+
390
+ If you want to compare a BLOB column, ` x'hex' ` or ` X'hex' ` are needed:
391
+
392
+ ```
393
+ $ lightning-cli sql -o "SELECT nodeid FROM nodes WHERE nodeid != x'03c9d25b6c0ce4bde5ad97d7ab83f00ae8bd3800a98ccbee36f3c3205315147de1';"
394
+ {
395
+ "rows": [
396
+ [
397
+ "0214739d625944f8fdc0da9d2ef44dbd7af58443685e494117b51410c5c3ff973a"
398
+ ],
399
+ [
400
+ "02ba9965e3db660385bd1dd2c09dd032e0f2179a94fc5db8917b60adf0b363da00"
401
+ ]
402
+ ]
403
+ }
404
+ $ lightning-cli sql -o "SELECT nodeid FROM nodes WHERE nodeid IN (x'03c9d25b6c0ce4bde5ad97d7ab83f00ae8bd3800a98ccbee36f3c3205315147de1', x'02ba9965e3db660385bd1dd2c09dd032e0f2179a94fc5db8917b60adf0b363da00')"
405
+ {
406
+ "rows": [
407
+ [
408
+ "02ba9965e3db660385bd1dd2c09dd032e0f2179a94fc5db8917b60adf0b363da00"
409
+ ],
410
+ [
411
+ "03c9d25b6c0ce4bde5ad97d7ab83f00ae8bd3800a98ccbee36f3c3205315147de1"
412
+ ]
413
+ ]
414
+ }
415
+ ```
416
+
417
+ Related tables are usually referenced by JOIN:
418
+
419
+ ```
420
+ $ lightning-cli sql -o "SELECT nodeid, alias, nodes_addresses.type, nodes_addresses.port, nodes_addresses.address FROM nodes INNER JOIN nodes_addresses ON nodes_addresses.row = nodes.rowid"
421
+ {
422
+ "rows": [
423
+ [
424
+ "02ba9965e3db660385bd1dd2c09dd032e0f2179a94fc5db8917b60adf0b363da00",
425
+ "YELLOWWATCH-22.11rc2-31-gcd7593b",
426
+ "dns",
427
+ 7272,
428
+ "localhost"
429
+ ],
430
+ [
431
+ "0214739d625944f8fdc0da9d2ef44dbd7af58443685e494117b51410c5c3ff973a",
432
+ "HOPPINGSQUIRREL-1rc2-31-gcd7593b",
433
+ "dns",
434
+ 7171,
435
+ "localhost"
436
+ ]
437
+ ]
438
+ }
439
+ ```
440
+
441
+ Simple function usage, in this case COUNT. Strings inside arrays need
442
+ ", and ' to protect them from the shell:
443
+
444
+ ```
445
+ $ lightning-cli sql 'SELECT COUNT(*) FROM nodes"
446
+ {
447
+ "rows": [
448
+ [
449
+ 3
450
+ ]
451
+ ]
452
+ }
453
+ ```
454
+
357
455
AUTHOR
358
456
------
359
457
0 commit comments