Closed wolfgangwalther closed 3 years ago
This looks super interesting, converting to JSON and leveraging the Postgres JSON parser is a very smart approach!
The tricky part in this query is to get the potentially nested TARGETENTRY
s right, converting to JSON solves that beautifully. I was playing with a fast but partially incorrect alternative solution here (on my megaquery2
branch). Your approach seems much more promising.
Some notes:
TARGETENTRY
format has not changed in the last 9 years.
When embedding views, the following breaks the detection algorithm:
What happens here is:
allSourceColumns
tries to parse the view definition in form of apg_node_tree
(https://www.postgresql.org/docs/current/catalog-pg-rewrite.html)COALESCE
)My current solution is to wrap another
SELECT
around theCOALESCE
- that works fine.I have played a bit with changing up the query in
allSourceColumns
- I think the structure ofpg_node_tree
does not allow a proper regex solution to really get rid of all sub-selects. However, I was able to apply a couple of transformations to the node tree to bring it to JSON format - which can easily be parsed for the embeddable columns. This was only tested with PG12 so far and also not very extensively, yet. (just noted that it fails on some of the pg_catalog views apparently - so there is definitely some more tweaking needed for thetransform_json
part)The query currently looks like this:
In theory this should allow a much more robust parsing of the view definition, but ONLY IF the json transformation works flawlessly.
Just thought I post that here, in case anyone wants to play with this, before I continue to.