Created
December 20, 2018 04:38
-
-
Save grahamu/6a80154246dedc03b6b0e084d372991e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT "realestate_db_building"."id", | |
"realestate_db_building"."public_notes", | |
"realestate_db_building"."public_notes_changed", | |
"realestate_db_building"."private_notes", | |
"realestate_db_building"."private_notes_changed", | |
"realestate_db_building"."name", | |
"realestate_db_building"."displayed", | |
"realestate_db_building"."website", | |
"realestate_db_building"."kind", | |
"realestate_db_building"."access", | |
"realestate_db_building"."access_details", | |
"realestate_db_building"."street", | |
"realestate_db_building"."city", | |
"realestate_db_building"."state", | |
"realestate_db_building"."lat", | |
"realestate_db_building"."lon", | |
"realestate_db_building"."contact_id", | |
"realestate_db_building"."boosted", | |
"realestate_db_building"."address_id", | |
SUM(CASE | |
WHEN "realestate_db_suite"."available_type" = %s THEN %s | |
ELSE %s | |
END) AS "displayed_suite_count", | |
(ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) AS "is_in_geojson_bounds", | |
COUNT("realestate_db_buildingphoto"."id") AS "photo_count", | |
(SELECT V0."available_changed" | |
FROM "realestate_db_suite" V0 | |
LEFT OUTER JOIN "taggit_taggeditem" V2 ON (V0."id" = V2."object_id" | |
AND (V2."content_type_id" = %s)) | |
WHERE (V0."building_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "realestate_db_building" U0 | |
LEFT OUTER JOIN "realestate_db_suite" U1 ON (U0."id" = U1."building_id") | |
LEFT OUTER JOIN "realestate_db_buildingphoto" U2 ON (U0."id" = U2."building_id") | |
WHERE (U0."displayed" = %s | |
AND (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) = %s) | |
GROUP BY U0."id", (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) | |
HAVING (SUM(CASE | |
WHEN U1."available_type" = %s THEN %s | |
ELSE %s | |
END) >= %s | |
AND COUNT(U2."id") >= %s)) | |
AND NOT (V0."available_type" = %s) | |
AND V0."rsf" BETWEEN %s AND %s | |
AND V2."tag_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "taggit_tag" U0 | |
WHERE U0."slug" IN (%s)) | |
AND V0."building_id" = ("realestate_db_building"."id")) | |
ORDER BY V0."available_changed" DESC | |
LIMIT 1) AS "latest_suite_availability" | |
FROM "realestate_db_building" | |
LEFT OUTER JOIN "realestate_db_suite" ON ("realestate_db_building"."id" = "realestate_db_suite"."building_id") | |
LEFT OUTER JOIN "realestate_db_buildingphoto" ON ("realestate_db_building"."id" = "realestate_db_buildingphoto"."building_id") | |
WHERE ("realestate_db_building"."displayed" = %s | |
AND (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) = %s | |
AND "realestate_db_building"."id" IN | |
(SELECT DISTINCT V0."building_id" AS Col1 | |
FROM "realestate_db_suite" V0 | |
LEFT OUTER JOIN "taggit_taggeditem" V2 ON (V0."id" = V2."object_id" | |
AND (V2."content_type_id" = %s)) | |
WHERE (V0."building_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "realestate_db_building" U0 | |
LEFT OUTER JOIN "realestate_db_suite" U1 ON (U0."id" = U1."building_id") | |
LEFT OUTER JOIN "realestate_db_buildingphoto" U2 ON (U0."id" = U2."building_id") | |
WHERE (U0."displayed" = %s | |
AND (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) = %s) | |
GROUP BY U0."id", (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) | |
HAVING (SUM(CASE | |
WHEN U1."available_type" = %s THEN %s | |
ELSE %s | |
END) >= %s | |
AND COUNT(U2."id") >= %s)) | |
AND NOT (V0."available_type" = %s) | |
AND V0."rsf" BETWEEN %s AND %s | |
AND V2."tag_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "taggit_tag" U0 | |
WHERE U0."slug" IN (%s)))) | |
AND | |
(SELECT V0."available_changed" | |
FROM "realestate_db_suite" V0 | |
LEFT OUTER JOIN "taggit_taggeditem" V2 ON (V0."id" = V2."object_id" | |
AND (V2."content_type_id" = %s)) | |
WHERE (V0."building_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "realestate_db_building" U0 | |
LEFT OUTER JOIN "realestate_db_suite" U1 ON (U0."id" = U1."building_id") | |
LEFT OUTER JOIN "realestate_db_buildingphoto" U2 ON (U0."id" = U2."building_id") | |
WHERE (U0."displayed" = %s | |
AND (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) = %s) | |
GROUP BY U0."id", (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) | |
HAVING (SUM(CASE | |
WHEN U1."available_type" = %s THEN %s | |
ELSE %s | |
END) >= %s | |
AND COUNT(U2."id") >= %s)) | |
AND NOT (V0."available_type" = %s) | |
AND V0."rsf" BETWEEN %s AND %s | |
AND V2."tag_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "taggit_tag" U0 | |
WHERE U0."slug" IN (%s)) | |
AND V0."building_id" = ("realestate_db_building"."id")) | |
ORDER BY V0."available_changed" DESC | |
LIMIT 1) >= %s) | |
GROUP BY "realestate_db_building"."id", (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))), | |
(SELECT V0."available_changed" | |
FROM "realestate_db_suite" V0 | |
LEFT OUTER JOIN "taggit_taggeditem" V2 ON (V0."id" = V2."object_id" | |
AND (V2."content_type_id" = %s)) | |
WHERE (V0."building_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "realestate_db_building" U0 | |
LEFT OUTER JOIN "realestate_db_suite" U1 ON (U0."id" = U1."building_id") | |
LEFT OUTER JOIN "realestate_db_buildingphoto" U2 ON (U0."id" = U2."building_id") | |
WHERE (U0."displayed" = %s | |
AND (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) = %s) | |
GROUP BY U0."id", (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) | |
HAVING (SUM(CASE | |
WHEN U1."available_type" = %s THEN %s | |
ELSE %s | |
END) >= %s | |
AND COUNT(U2."id") >= %s)) | |
AND NOT (V0."available_type" = %s) | |
AND V0."rsf" BETWEEN %s AND %s | |
AND V2."tag_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "taggit_tag" U0 | |
WHERE U0."slug" IN (%s)) | |
AND V0."building_id" = ("realestate_db_building"."id")) | |
ORDER BY V0."available_changed" DESC | |
LIMIT 1) | |
HAVING (SUM(CASE | |
WHEN "realestate_db_suite"."available_type" = %s THEN %s | |
ELSE %s | |
END) >= %s | |
AND COUNT("realestate_db_buildingphoto"."id") >= %s) | |
ORDER BY | |
(SELECT V0."available_changed" | |
FROM "realestate_db_suite" V0 | |
LEFT OUTER JOIN "taggit_taggeditem" V2 ON (V0."id" = V2."object_id" | |
AND (V2."content_type_id" = %s)) | |
WHERE (V0."building_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "realestate_db_building" U0 | |
LEFT OUTER JOIN "realestate_db_suite" U1 ON (U0."id" = U1."building_id") | |
LEFT OUTER JOIN "realestate_db_buildingphoto" U2 ON (U0."id" = U2."building_id") | |
WHERE (U0."displayed" = %s | |
AND (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) = %s) | |
GROUP BY U0."id", (ST_Contains(ST_GeomFromEWKT(%s), ST_SetSRID(ST_Point("lon", "lat"), 4326))) | |
HAVING (SUM(CASE | |
WHEN U1."available_type" = %s THEN %s | |
ELSE %s | |
END) >= %s | |
AND COUNT(U2."id") >= %s)) | |
AND NOT (V0."available_type" = %s) | |
AND V0."rsf" BETWEEN %s AND %s | |
AND V2."tag_id" IN | |
(SELECT U0."id" AS Col1 | |
FROM "taggit_tag" U0 | |
WHERE U0."slug" IN (%s)) | |
AND V0."building_id" = ("realestate_db_building"."id")) | |
ORDER BY V0."available_changed" DESC | |
LIMIT 1) DESC NULLS LAST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parameters?