Skip to content

View Editor Loses formatting between edits #9838

Closed as not planned
Closed as not planned

Description

@TorsionTools

Describe the bug

The formatting of the View editor is not retained between editing sessions.
This is especially annoying when it moves things that were put on separate lines for complex joins or concat and make them single lined and hard to read / see.

To Reproduce

Open the View Editor and us the automatic formatting CTRL + K.
Save
Open the View Editor again and the formatting has been lost.

Expected behavior

Formatting to be retained between saves.

Activity

  1. TorsionTools commented on Apr 20, 2026

    @TorsionTools
    Author

    As a follow up to this, I have noticed in the latest version 9.14 that just using the auto formatting for the View editor will cause the view editor to throw an error and not let you save.

    Opened a view, used ctrl + K for formatting, tried to Save:
    Image

    Here are the formatting rules that are currently set.
    Image

  2. dpage commented on Oct 15, 2026

    @dpage
    Contributor

    There are two parts to this.

    The error when saving after Ctrl+K is fixed in #10591. The dialog checks whether an edited definition changes the view's columns by comparing the text before FROM, and that comparison was case-sensitive, so the formatter changing the case of function names, types or keywords looked like a column change and triggered the drop-and-recreate warning. The comparison now ignores case and formatting (outside quoted identifiers and string literals).

    Keeping your own formatting between edits isn't something pgAdmin can do, unfortunately. PostgreSQL doesn't store the text of a view's definition: it stores the parsed query, and pg_get_viewdef() rebuilds the SQL from that every time it's read, so line breaks, indentation and comments are lost as soon as the view is saved, whichever tool created it. The usual workaround is to keep the formatted source in a file or in version control.

  3. dpage commented on Oct 15, 2026

    @dpage
    Contributor

    The follow-up bug, where reformatting a view's SQL was treated as a column change that dropped and re-created the view, is fixed in 3530761 (#10591).

    Keeping the view's original formatting isn't possible, however: PostgreSQL doesn't store the text of the view definition, only its parsed form, and pgAdmin reads it back with pg_get_viewdef(), which regenerates the SQL in PostgreSQL's own layout. Any formatting applied when the view was created is lost on the server side before pgAdmin ever sees it.

  4. dpage commented on Oct 16, 2026

    @dpage
    Contributor

    Closing: the follow-up bug is fixed in 3530761 (#10591), and keeping a view's original formatting isn't possible for the reason above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions