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