Skip to content
Noboru Saito edited this page May 7, 2018 · 8 revisions

Welcome to the trdsql wiki!

trdsql

Execute SQL to CSV, TSV, LTSV, JSON

Alternative usage

Clarity of command output

Ignore the space before and after the delimiter. So, it can be used in the shaping of the output of the command.

$ ps |trdsql -oat -ih -id " " "SELECT * FROM -"
+-------+-------+----------+--------+
|  PID  |  TTY  |   TIME   |  CMD   |
+-------+-------+----------+--------+
| 11704 | pts/2 | 00:00:00 | ps     |
| 11705 | pts/2 | 00:00:00 | trdsql |
| 23171 | pts/2 | 00:00:27 | zsh    |
+-------+-------+----------+--------+

Add header

You can give another name by AS. If you want to change the output name.

trdsql -ojson "SELECT c1 as id ,c2 as name FROM test.csv"
[
  {
    "id": "1",
    "name": "Orange"
  },
  {
    "id": "2",
    "name": "Melon"
  },
  {
    "id": "3",
    "name": "Apple"
  }
]

When you want to name a table column. Add item name to CSV without header line.

$ cat <(echo id,name) test.csv|trdsql -ojson -ih "SELECT * FROM  -"
[
  {
    "id": "1",
    "name": "Orange"
  },
  {
    "id": "2",
    "name": "Melon"
  },
  {
    "id": "3",
    "name": "Apple"
  }
]
Clone this wiki locally