aboutsummaryrefslogtreecommitdiff
path: root/src/queries.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/queries.h')
-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;";