Skip to content

Instantly share code, notes, and snippets.

@simonneutert
Created September 1, 2025 19:22
Show Gist options
  • Select an option

  • Save simonneutert/f71a507d67142a2d59152f917bff9654 to your computer and use it in GitHub Desktop.

Select an option

Save simonneutert/f71a507d67142a2d59152f917bff9654 to your computer and use it in GitHub Desktop.

Revisions

  1. simonneutert created this gist Sep 1, 2025.
    6 changes: 6 additions & 0 deletions demo.csv
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    name;group;subgroup;type
    abc;1;a;x
    def;2;b;y
    ghi;3;c;z
    jkl;4;d;x
    mno;5;e;y
    54 changes: 54 additions & 0 deletions demo_data_sq.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    # https://sq.io/docs/drivers/csv#delimiters
    sq add ./demo.csv --driver.csv.delim=semi --ingest.header

    # https://sq.io/docs/drivers/csv#monotable
    sq '@demo.data | .type | uniq' -j

    # [
    # {
    # "type": "x"
    # },
    # {
    # "type": "y"
    # },
    # {
    # "type": "z"
    # }
    # ]

    sq '@demo.data | .type | uniq' -j | jq '{typ: [.[] | .type]}'

    # {
    # "typ": [
    # "x",
    # "y",
    # "z"
    # ]
    # }

    sq sql 'SELECT distinct(type) from data' -j

    # [
    # {
    # "type": "x"
    # },
    # {
    # "type": "y"
    # },
    # {
    # "type": "z"
    # }
    # ]

    sq sql 'SELECT distinct(type) from data' -j | jq '{typ: [.[] | .type]}'

    # {
    # "typ": [
    # "x",
    # "y",
    # "z"
    # ]
    # }

    # write to a new csv
    sq sql 'SELECT distinct(type) from data' --csv --output=x.csv