Usage of Dataview function "extract"

I’m a lazy note-taker, so I keep a daily note in which I collect everything that wants out of my head.

The “log” (Logbuch in my native German) is exactly that heap. Mostly I use it for notes on programming, where I need a short note plus a screenshot. It has the form:

- (Logbuch:: <some_word>) #tag_for_project entry text, possibly with further #tags
   - childentry with text and yet more tags
   - Screen:: ![[some_image]]
   - another child with text

My current query flattens file.lists into L and spills out the rows.L.text, rows.L.children. Good enough for the text entries. Unfortunately it drops dead on the images.

TABLE rows.L.text as Text, flat(rows.L.children,2).text as Kommentar
FROM #Logbuch and #tag_for_project
FLATTEN file.lists AS L
WHERE file.lists
WHERE meta(L.section).subpath = "Logbuch"
WHERE contains(L.tags, "#tag_for_project")
group by as Datum
sort date(file.ctime) desc

As you can see, the fields “Screen” are rendered with the sizing information as text only. That’s somewhat annoying. If I just have a ![[some_image]] on that line without any size or as value of key “Screen::”, Dataview renders it quite nicely, but that’s not what I want.

Well, I’m not easily scared, so I tried regreplace’ing within the line containing an image, simply using choice to either embed or render the text, codediving into Dataview, even things not talked about in polite society such as this.

All because I couldn’t get the function “extract” to work and didn’t find anybody using it at all, much less an example. Link to documentation: Functions - Dataview

Now I’m so censored, that I’m ripe to call on you folks for help :wink:

So, if anybody could (pretty please!) explain that function to me or show me a working example, I’d be grateful. And my neighbours would add their thanks, just to be relieved of the blue air here.

What I want is a table with ID, that contains the field “Text” and a proper representation of the value of “Screen” in the children.

P.S.: I don’t want to use JS. That would be cheating :wink:

Update on the research: Extract works if I don’t have a GROUP BY. It does work on already flattened lists, though.

Now: How to work around the GROUP BY…

TWIMC :slight_smile: Just in case, someone kicks the same stones as I.

I ended up by FLATTEN and using object(). This is what the query looks like, extracting the hell of each and everything.

Lessons learned: If a field is null, DataView doesn’t return the field at all, thus reducing the number of fields. To prevent that, I cast the potentially empty field (not each List has a child with the Screen-Field) into a new object, adding a field “empty” with the value “”.

Table (choose from X)
FROM #Logbuch and #some_tag and "Daylies"
FLATTEN file.lists as L
FLATTEN object("Lvl1", L.children, "empty", "") as A
FLATTEN object("Screen", A.Lvl1.Screen, "child_line", A.Lvl1.line, "parent_line", L.line, "text", A.Lvl1.text, "empty", "") as A1
FLATTEN object("Logbuch", L.Logbuch, "flink",, "llink",, "outlinks", L.outlinks, "section", L.children.section, "parent_line", L.line, "parent_path", L.path, "text", L.text, "tags", L.tags, "child_text", A1.text, "child_tags", A.Lvl1.tags, "c_children", A.Lvl1.children, "Screen_line", A1.child_line, "Screen", A1.Screen, "empty", "") as X
WHERE file.lists
WHERE contains(L.Logbuch, "some_project")
WHERE contains(L.tags, "some_tag")
where !=

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.