Thread: contribute pg_get_viewdef2 et al

contribute pg_get_viewdef2 et al

From
Andreas Pflug
Date:
Tom,

when I made the proposal to reduce the number of parentheses emitted by 
pg_get_viewdef and the other routines implemented in ruleutils.c, you 
were quite declining on this, stating that any erroneous left out pair 
of parentheses would screw up pg_dump's backup files, making a restore 
fail to reproduce the exact database state.

As an alternative, I now implemented pg_get_viewdef2, pg_get_ruledef2, 
pg_get_expr2 doing the same stuff as the versions without '2', but 
omitting parentheses not needed (hopefully, review appreciated) in a 
contribute module. pgadmin3 will use these versions, if present, or fall 
back to the standard versions. Additionally, pgadmin3 will indent and 
add crlf, which could be done inside pg_get_xxxx2 too.

I think this way we have both: secure but human unreadable form for 
backup/restore, and a better readable form for user interface.
Actually, a third way, preserving the original query in a dedicated 
pg_rewrite column, would be even better for this purpose, because 
formatting and comments wouldn't be stripped which can be quite helpful 
after some months to know what's happening. AFAICS this would require 
pg_dump/pg_restore to save and update this column after creating the 
view from pg_get_ruledef().

Regards,

Andreas