reddit / emacs

Do org tables have a means of filtering the records by some column value?

vfclists · 2022-05-28 10:46
Something tells me they do, but I can't find any appropriate function for it, unless it is just my imagination. Guys please don't tell me it org-table has no such functionality built in.
[deleted] · 2022-05-28 11:11
[deleted]
sunnyata · 2022-05-28 13:22
Yes you can, using org-babel https://emacs.stackexchange.com/questions/20129/how-can-i-filter-table-in-org-mode
dpoggio · 2022-05-28 15:29
That’s great. Any solutions without `cl`?
sunnyata · 2022-05-29 08:43
Not in org AFAIK. Maybe ses (simple Emacs spreadsheet) does it, I dunno.
yantar92 · 2022-05-29 11:10
You can use any other Elisp loop facility. Or not Elisp, but any other programming language.
sachac · 2022-05-30 03:16
seq-filter, perhaps?
ffellirm · 2022-05-30 03:59
As others have said, with source code blocks you could process the table in any language you like. One option is [ob-dsq](https://github.com/fritzgrabo/ob-dsq). Thanks to [/u/fritzgrabo](https://old.reddit.com/user/fritzgrabo). ([earlier reddit post](https://old.reddit.com/r/emacs/comments/u1hf9d/ann_obdsqel_use_sql_to_join_and_query_json_csv/)) [ob-dsq](https://github.com/fritzgrabo/ob-dsq) gives org source block support for the command line tool [dsq](https://github.com/multiprocessio/dsq). This lets you query an org-mode table with SQL. So that's good if you know SQL. And is more powerful than just simple column filtering. For example #+name: foods | item | rating | size | |--------+--------+------| | burger | 2 | 200 | | salami | 1 | 300 | | apple | 5 | 100 | | pizza | 3 | 500 | | cake | 2 | 300 | #+begin_src dsq :input foods SELECT * FROM {} where rating>=2 and size > 200 order by rating desc #+end_src #+RESULTS: | item | rating | size | |-------+--------+------| | pizza | 3 | 500 | | cake | 2 | 300 | (it can also be used to query external files like excel spreadsheets and return the results in an org-mode table) So that could be useful (One small thing is that the column order in the returned results doesn't seem to be strictly defined. So it doesn't necessarily follow the order of columns in the SELECT statement, and doesn't seem to be consistent across repeated calls. That seems a little odd and would be nice if it were fixed in future)
vfclists · 2022-05-30 11:29
Nice!!
simbledress · 2022-06-04 09:16
The [orgaggregate](https://github.com/tbanel/orgaggregate) package lets you do that and more.
noman_032018 · 2022-06-08 05:30
There's [seq-filter](https://www.gnu.org/software/emacs/manual/html_node/elisp/Sequence-Functions.html#index-seq_002dfilter).