aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2024-01-29 22:05:04 -0600
committerMichael McVady <femtonaut@gmail.com>2024-01-29 22:05:04 -0600
commit222ecc27bc86de1e74e871c14e247a11c5564d73 (patch)
tree92700c9c7fd7bfbcc5d5d016e52a06b17dbdc6f3
parentdcfd05a7faf8ffd4f32383e8f9fcbfbd5b4e29ab (diff)
Fix sorting of index
-rw-r--r--src/queries.h22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/queries.h b/src/queries.h
index 7b5b55d..6c11317 100644
--- a/src/queries.h
+++ b/src/queries.h
@@ -4,19 +4,23 @@ const char *q_select_entry =
"WHERE id = $1;";
const char *q_select_entries =
-"SELECT id, title, created_at::DATE, updated_at::DATE, body "
-"FROM entries "
-"ORDER BY updated_at DESC, created_at DESC "
-"LIMIT $1;";
+"WITH inner_query AS "
+"( "
+" SELECT id, title, created_at, updated_at, body "
+" FROM entries "
+" ORDER BY updated_at DESC, created_at DESC "
+" LIMIT $1 "
+") "
+"SELECT id, title, created_at::DATE, updated_at::DATE, body FROM inner_query;";
const char *q_search_entries =
"WITH search_query AS "
"( "
-" SELECT id, title, created_at::DATE, updated_at::DATE, body, "
-" TS_RANK(search_vector, TO_TSQUERY('english', $1)) AS rank "
-" FROM entries "
-" WHERE search_vector @@ TO_TSQUERY('english', $2) "
-" ORDER BY rank DESC "
+" SELECT id, title, created_at::DATE, updated_at::DATE, body, "
+" TS_RANK(search_vector, TO_TSQUERY('english', $1)) AS rank "
+" FROM entries "
+" WHERE search_vector @@ TO_TSQUERY('english', $2) "
+" ORDER BY rank DESC "
" LIMIT $3 "
") "
"SELECT id, title, created_at::DATE, updated_at::DATE, body FROM search_query;";