Hi, Dirkjan Bussink reported that a view using CYCLE markers 'Y' and 'N' cannot be recreated from pg_get_viewdef output. The deparser emits TO 'Y'::text DEFAULT 'N'::text, but the CYCLE grammar rejects the casts. This also breaks dump/restore of such views.
The attached patch allows casts and parentheses around CYCLE literals, while continuing to reject general expressions. It also fixes a separate crash in pg_get_viewdef for domain markers: the default-Boolean check assumes that both markers are bare Const nodes, which need not be true for domain or typmod coercions. Allowing explicit casts also introduces a way to invoke volatile user-defined cast functions in cycle marks. The patch rejects these, since repeated evaluation of a changing mark can defeat cycle detection. The check runs after common-type coercion and also catches a pre-existing case: volatile implicit casts applied to otherwise valid literal marks. Tests cover both the newly allowed explicit-cast syntax and the existing implicit-cast case. There is a back-branch compatibility question here. The implicit-cast case already parses on existing releases, and applying this volatility check would prevent views using such casts from restoring after a minor upgrade. Although the case requires a volatile user-defined implicit cast and already has unreliable cycle detection, should we keep the volatility check master-only? Another option is to check explicit casts on back branches while preserving the existing implicit-coercion behavior. The grammar and deparser fixes themselves are candidates for back-patching to 14, where SEARCH and CYCLE were introduced. The usual sanity checks and tests have been performed on 20devel. The regression tests include ten representative marker pairs, view recreation in both output formats, visible domain-view deparser output, and rejection of general expressions and volatile casts. Regards, Nikhil Sontakke PlanetScale
v1-0001-Fix-CYCLE-clause-deparsing-and-dump-restore.patch
Description: Binary data
