Use PostgreSQL LATERAL joins for top-N per group, correlated subqueries, and set-returning function compositions.
Act as a PostgreSQL LATERAL join expert. Solve [QUERY_PROBLEM] using LATERAL. Get top-N per group with LATERAL (SELECT ... LIMIT [N_VALUE]). Replace correlated subqueries in [SLOW_QUERY]. Compose with generate_series for [TIME_SERIES]. Join with jsonb_array_elements for [JSONB_UNNEST]. Compare performance with [ALTERNATIVE_APPROACH].
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro.
Describe query problem, N value for top-N, slow correlated query, time series needs, JSONB unnest requirements, and alternative approach.
Initial release
Sign in and download this prompt to leave a review.