+
+#mode user group hash mtime csvtags path
+
+sqlite3 $pkgfile <<-EOS
+.header on
+select
+ printf('%s %s %s %s %s %s',
+ F.mode, F.username, F.groupname,
+ case when F.filetype = 'c' then
+ F.devmajor || ',' || F.devminor
+ else
+ F.hash
+ end
+ ,strftime('%Y-%m-%dT%H:%M:%S', F.mtime, 'unixepoch')
+ , T.tags
+ ,F.path)
+from packagefiles as F
+left join (
+ select TG.package, TG.version, TG.release, TG.path
+ ,coalesce(group_concat(tag), '-') as tags
+ from packagefiletags TG
+ group by package, version, release, path
+) T
+on T.package = F.package and T.version = F.version and T.release = F.release
+and T.path = F.path
+-- apparently going to have to do this in C because there's
+-- no way to order the aggregated tags
+where
+'$pkg' = F.package||'-'||F.version||'-'||F.release
+;
+EOS
+}