Skip to content

Instantly share code, notes, and snippets.

@Deepwalker
Created June 17, 2014 11:06
Show Gist options
  • Save Deepwalker/0dcf2849ca4317638033 to your computer and use it in GitHub Desktop.
Save Deepwalker/0dcf2849ca4317638033 to your computer and use it in GitHub Desktop.
SELECT array_to_json(array_agg(row_to_json(t)))
FROM
(SELECT id, text, Cast(created_at AS text),
likes_count,
CASE
WHEN l.value THEN TRUE
ELSE FALSE
END AS liked
FROM posts
LEFT OUTER JOIN
(SELECT post_id,
TRUE AS value
FROM likes
WHERE user_id = 1) AS l ON l.post_id = posts.id LIMIT 100) AS t;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment