WITH geom AS
(
	SELECT 'SRID=4326;POLYGON((-4 1,-3 1,-3 2,-4 2,-4 1))'::geometry AS a,
		'\x0106000000010000000103000000010000009800000001000000000008c001000000000026400f677e35074807c001000000000026401dcefc6a0e9006c00100000000002640f2d24d6210d805c00100000000002640003acc97172005c001000000000026400ea14acd1e6804c001000000000026401d08c90226b003c001000000000026402b6f47382df802c0010000000000264039d6c56d344002c00100000000002640473d44a33b8801c001000000000026401c42959a3dd000c001000000000026402ba913d0441800c001000000000026407120240b98c0febf01000000000026408eee2076a650fdbf0100000000002640aabc1de1b4e0fbbf0100000000002640c68a1a4cc370fabf0100000000002640e35817b7d100f9bf01000000000026408d62b9a5d590f7bf0100000000002640aa30b610e420f6bf0100000000002640c6feb27bf2b0f4bf0100000000002640e2ccafe60041f3bf0100000000002640ff9aac510fd1f1bf01000000000026401b69a9bc1d61f0bf01000000000026406e6e4c4f58e2edbf0100000000002640c481902c6002ebbf0100000000002640fc1d8a027d22e8bf010000000000264035ba83d89942e5bf01000000000026406d567daeb662e2bf01000000000026404ce5ed08a705dfbf0100000000002640bd1de1b4e045d9bf01000000000026406844696ff085d3bf0100000000002640b2f9b836548ccbbf0100000000002640946a9f8ec70cc0bf0100000000002640db6d179aeb34a2bf01000000000026409bce4e0647c9ab3f0100000000002640c442ad69de71c23f0100000000002640e2d1c6116bf1cd3f010000000000264046425bcea5b8d43f0100000000002640d50968226c78da3f0100000000002640b2683a3b191ce03f010000000000264079cc4065fcfbe23f01000000000026404130478fdfdbe53f010000000000264008944db9c2bbe83f0100000000002640b38009dcba9beb3f01000000000026407ae40f069e7bee3f010000000000264021240b98c0adf03f010000000000264005560e2db21df23f0100000000002640e88711c2a38df33f0100000000002640ccb9145795fdf43f0100000000002640b0eb17ec866df63f010000000000264005e275fd82ddf73f0100000000002640e9137992744df93f0100000000002640cc457c2766bdfa3f0100000000002640b0777fbc572dfc3f010000000000264094a98251499dfd3f010000000000264077db85e63a0dff3f0100000000002640e6e8f17b9b3e00400100000000002640d881734694f600400100000000002640ca1af5108dae01400100000000002640bcb376db856602400100000000002640ae4cf8a57e1e03400100000000002640a0e5797077d603400100000000002640917efb3a708e04400100000000002640bc79aa436e4605400100000000002640ae122c0e67fe05400100000000002640a0abadd85fb60640010000000000264092442fa3586e0740010000000000264001000000000008400100000000002640f29881caf8b708400100000000002640e4310395f16f094001000000000026400f2db29def270a40010000000000264001c63368e8df0a400100000000002640f35eb532e1970b400100000000002640e4f736fdd94f0c400100000000002640d690b8c7d2070d400100000000002640c8293a92cbbf0d4001000000000026400100000000000e4001000000000026400100000000000e40268dd13aaaaa2540983446eba8aa0e405ac0046edd5d2540983446eba8aa0e40268dd13aaa2a25409cfeec478a880e40cdcccccccccc244069cbb91457550d406766666666e62440983446eba8aa0c400ea661f888882440650113b875770d405ac0046edd5d244069cbb91457550d403433333333332440983446eba8aa0c406766666666e62340369886e123220c4041d9942bbcbb2340983446eba8aa0a408df337a110912340036553aef0ee0a405ac0046edd5d2340369886e123220a40db722ec555552340ff9aac510f110940db722ec555d52240983446eba8aa0840343333333333224032cedf8442440640a73ffb91222222400100000000000640740cc85eef6e204069cbb914575505409a99999999991f40cb67791edcdd054019e76f4221221e4032cedf8442440640e6b33c0feeee1d40369886e123220640b38009dcbabb1d40cb67791edcdd0540b38009dcbabb1d40cb67791edcdd05401b4cc3f011111d40676666666666064019e76f4221221c40cf31207bbdbb0540b38009dcbabb1b400100000000000640b38009dcbabb1b4001000000000006406766666666661b40cb67791edcdd05401b4cc3f011111b4032cedf84424406401b4cc3f011111b40369886e123220640cdcccccccccc1a40010000000000064082b2295778f719400100000000000640e7c6f48425de18400100000000000640e6b33c0feeee1740010000000000064001000000000017404c1aa37554551a4001000000000008404c1aa37554551a40b5e55c8aabaa10c04c1aa37554551a4081b22957787717c001000000000008c08df337a1101123c001000000000008c09a9999999999fdbf01000000000008c086eb51b81e85074001000000000008c00100000000000c4001000000000008c0b91e85eb5138114001000000000008c0b38009dcbabb1240cdcccccccccc08c06766666666661440cb67791edcdd05c081b2295778771440369886e1232206c03433333333331640cdcccccccccc06c09a9999999999164069cbb914575507c081b22957787716409a999999999907c0cdcccccccccc1640369886e1232208c0cdcccccccccc1640369886e1232208c06766666666661740f7b4c35f937509c0dcf97e6abc941940cc67791edcdd09c00100000000001a40cf31207bbdbb09c01b4cc3f011111b4032cedf84424408c04e7ff62345441c40650113b8757707c00100000000001e40514eb4ab903207c060d218ada34a1e4032cedf84424406c09a99999999991f40ff9aac510f1105c08df337a110112040026553aef0ee04c041d9942bbc3b204000000000000004c06766666666662040983446eba8aa04c08df337a11091214034333333333305c06766666666e62140369886e1232206c0268dd13aaa2a224069cbb914575505c00ea661f8888822409a999999999905c00ea661f88808234032cedf84424406c05ac0046edd5d2340cb67791edcdd05c0268dd13aaaaa234001000000000006c041d9942bbcbb234067666666666606c09a99999999192440369886e1232206c0f3599e0777772440cdcccccccccc06c09a9999999999244032cedf84424406c0cdcccccccccc24409a999999999907c041d9942bbc3b254001000000000008c00100000000002640'::bytea::geography AS b
)
, inter AS
(
	-- Both input polygons are valid when cast to geometry
	SELECT ST_IsValid(a) AS a_valid, ST_IsValid(b::geometry) AS b_valid
		, ST_Intersection(a::geometry, b::geometry) AS tile
	FROM geom
)
-- Intersection: POLYGON((-3 2,-3 2,-3 1,-3 1,-3 2))
SELECT ST_AsText(tile)
	-- Intersection is reported to be valid
	, ST_IsValid(tile) AS tile_valid
	-- But it's not really! Geography intersection with a LINESTRING that just touches it returns the whole line:
	-- LINESTRING(-20 0,-3 0.999999998883122)
	, ST_AsText(ST_Intersection(tile::geography, 'LINESTRING(-20 0,-3 1)'::geography))
FROM inter
