Is it possible to check if a field exists?
I tried with date-started = null, and it seems that this treats files with Date Started:: and files without this field both as null. Is it possible to distinguish these two cases?
Good point, I'm not sure you can differentiate in normal Dataview; will add support for this.
Is it possible to achieve this with dataviewjs then? I would like to try it for now, and would really appreciate it if you can illustrate this with an example. 😃
It's possible in dataviewjs - dv.pages(<query).where(p => "date-started" in p).
Thanks for the solution. I have a follow-up question regarding this. After some testing, it seems that
- Query 1:
dv.pages(<query).where(p => "date-started" in p)gives files that have the field Date Created and with values in it. - Query 2: I was expecting that
dv.pages(<query).where(p => !("date-started" in p))would give files that do not have the field Date Created included. Instead, it also gives files have the field Date Created but with no values in it.
I was trying to use some kind of regular expression to separate the two cases in Query 2 but with no luck. Is there a workaround to separate the following files?
- Files that have Date Created and with values, i.e. date like 2021-06-19
- Files that have Date Created but with not values
- Files that do not have Date Created
That seems wierd - pages with something like Date Created:: should have a date-created field that is set to null, whereas pages without it should not have the key at all.
I believe contains() should work for this. Can you please try it out and let us know?
I believe
contains()should work for this. Can you please try it out and let us know?
What would be the syntax for using contains()? Is it possible to distinguish the following?
- Files that have Date Created and with values, i.e. date like 2021-06-19
- Files that have Date Created but with no values
- Files that do not have Date Created
Not entirely sure since it would depend on the indexing but you can do contains(file, "section") to check attributes on a specific object.
It seems like we're missing something to refer to the file being queried as an object in itself. Doing = contains(this, "date-started") works as intended, but doing something like contains(row, "date-started") doesn't return anything (since row seems to get its value when actually referencing an index.
So do anybody now what would be the equivalent of this for the current file being queried? The page/row object, so to speak.
this should be the current file object AFAIK. I'm out of touch with DV's source so no idea what row refers to. What is the use case at hand?
The use case is to differ between the defined but null, or not defined in a query. A silly query to showcase this scenario:
```dataview
TABLE contains(this, "date-created"), contains(row, "date-created"), row[date-created]
LIMIT 5
```
Here the first column would always show whether date-created is defined in the current file, but the second case to show whether date-created is defined in the first five file of your vault doesn't work. And I'm looking for what kind of expression would work for that case. (And row can be used to do row[date-created], and is used to allow for having fields like where or sort or similar, which otherwise would be interpreted as part of the query language)
The above query in my test vault displays as:
And ideally I would like for the second column in the third and fifth row to actually show "true". In the fifth row, it's defined but don't have any value, which is the case we're trying to discern in this thread.