Some basic use examples of typcial Obsidian queries - Please
Closed this issue · 4 comments
I have tried finding simple examples of the use of AlaSQL in the most mundane of cases. Just getting a list of all unique values from an array field.
I can't seem to find any examples.
I've used several AI Assistants, feeding them documents, examples, etc. I still cannot get the simplest use case working.
If there is a tutorial link, that would be great.
One pertinent use case is the ability to extract unique tags from the obsidian_notes
table where tags are stored as arrays. Currently, there seems to clear method for handling such nested array structures directly within AlaSQL queries in QATT.
I'm sure this is extremely simple, I just can't get it working.
Example Query:
Here's an example of a query that I would like to execute to get all unique tags from the obsidian_notes
table:
query: |
SELECT DISTINCT tag
FROM (
SELECT tags AS tag
FROM obsidian_notes
WHERE tags IS NOT NULL AND tags != ''
)
template: |
{{#each result}}
- {{tag}}
{{/each}}
postRenderFormat: micromark
*This returns concatenated arrays of the tags field from each note, instead of each of the tags.
If I can get the basic queries working, I'd be happy to create and supply a set of examples that most people would be expecting to use with Obsidian notes.
Tags is an array, well should always be, fixed a bug in new patch that makes sure a single entry is still treated as an array of one. Will release shortly.
In database terms digging into a value of a column like that is not really an expected thing to do. So there are a few options.
- I can make a new table which is all unique tags against all pages or just pulled from the store Obsidian has, not sure what it looks like but possible.
- Use this query which pulls all the tags out assuming you have no more than 10 tags on a page. If you do you just add more rows to increase the index up and join.
query: |
SELECT DISTINCT tag
FROM (
SELECT tags->0 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->1 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->2 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->3 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->4 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->5 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->6 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->7 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->8 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->9 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->10 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->11 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->12 AS tag FROM obsidian_notes
UNION ALL
SELECT tags->13 AS tag FROM obsidian_notes
)
WHERE tag <> ''
ORDER BY tag
template: |
{{#each result}}
- {{tag}}
{{/each}}
postRenderFormat: micromark
Release 1.1.1 will fix the tags array issue.
https://github.com/sytone/obsidian-queryallthethings/releases/tag/1.1.1
@RitchieMatt does this help and can I close the issue or move to a discussion?
No response, moving it to discussion so others can see.