Custom Column Order from `query`

I am working on porting all my old SilverBullet space script & queries over to space-lua & Lua Integrated Queries. Most of this has been straightforward but one thing that has not worked the way I expected is in LIQ column order

What I want: a table with columns “Name”, “Location”, and “Tags” in that order

How I’m trying to do this:
${query[[from index.tag "organization" select {name = renderOrganizationName(name, url), location = renderLink(location), tags = table.concat(tags, ", ")}]]}

Where renderOrganizationName and renderLink apply some rules & formatting before returning a string

What I didn’t expect: The resulting table, instead of following the order of the columns specified in the query (name, location, and then tags) is coming back (tags, location, and then name). I’ve tried changing the order of the columns in the query to no avail.

I know I can try to construct a table using space-lua but it feels like query[[...select...]] should just respect the column order provided and so I thought I’d ask if there was a setting I’m missing / some trick to get this to work I haven’t thought of

I`m afraid, that does not really help or even fix your problem, but here on my instance it comes out completely fine and as expected.
I get exactly the order of headers like they are positioned in the select statement.

For testing, I even implemented some functions, but same correct behavior…
Did you try it wothout your functions, too? Like ${query[[from index.tag "organization" select {name = name, location = location, tags=tags} ]]}

I wonder, what is wrong on your end :frowning:
Just for reference, I’m working on 2.0.0. pre4-18

I have skimmed through the code a bit and I don’t really see where they should be reordered, but it also isn’t really enforced in the code.
I guess the easy way out is to just do custom rendering

Thanks @zeus-web and @MrMugame

  • I did try it without functions and then it renders in the order I want it to (i.e. ...select {name=name, location=location, tags=tags} sorts as expected)
  • Just adding table.concat does not seem to break the “correct order” (i.e. ...select {name=name, location=location, tags=table.concat(tags, ", ")} sorts as expected)
  • But when I add my renderLink and renderOrganizationName functions, is when the order ceases to be mine

For now, I’ve built a space-lua function which executes the query and then uses template.each to construct Markdown rows and then tacks it on with the headers I want. But please do let me know if you guys ever figure this one out as I’d hate to have to do this for every table where I apply some kind of rendering function on a column…