supabase-community / postgres_lsp

A Language Server for Postgres
https://supabase.com
MIT License
3.24k stars 61 forks source link

feat: support "create view" with relpersistence #65

Closed cvng closed 9 months ago

cvng commented 9 months ago

What kind of change does this PR introduce?

Follow-up for #63, #51

What is the current behavior?

Parser panics

What is the new behavior?

Parser returns:

        ViewStmt(
            ViewStmt {
                view: Some(
                    RangeVar {
                        catalogname: "",
                        schemaname: "",
                        relname: "comedies",
                        inh: true,
                        relpersistence: "t",
                        alias: None,
                        location: 33,
                    },
                ),
                aliases: [],
                query: Some(
                    Node {
                        node: Some(
                            SelectStmt(
                                SelectStmt {
                                    distinct_clause: [],
                                    into_clause: None,
                                    target_list: [
                                        Node {
                                            node: Some(
                                                ResTarget(
                                                    ResTarget {
                                                        name: "",
                                                        indirection: [],
                                                        val: Some(
                                                            Node {
                                                                node: Some(
                                                                    ColumnRef(
                                                                        ColumnRef {
                                                                            fields: [
                                                                                Node {
                                                                                    node: Some(
                                                                                        AStar(
                                                                                            AStar,
                                                                                        ),
                                                                                    ),
                                                                                },
                                                                            ],
                                                                            location: 52,
                                                                        },
                                                                    ),
                                                                ),
                                                            },
                                                        ),
                                                        location: 52,
                                                    },
                                                ),
                                            ),
                                        },
                                    ],
                                    from_clause: [
                                        Node {
                                            node: Some(
                                                RangeVar(
                                                    RangeVar {
                                                        catalogname: "",
                                                        schemaname: "",
                                                        relname: "films",
                                                        inh: true,
                                                        relpersistence: "p",
                                                        alias: None,
                                                        location: 59,
                                                    },
                                                ),
                                            ),
                                        },
                                    ],
                                    where_clause: None,
                                    group_clause: [],
                                    group_distinct: false,
                                    having_clause: None,
                                    window_clause: [],
                                    values_lists: [],
                                    sort_clause: [],
                                    limit_offset: None,
                                    limit_count: None,
                                    limit_option: Default,
                                    locking_clause: [],
                                    with_clause: None,
                                    op: SetopNone,
                                    all: false,
                                    larg: None,
                                    rarg: None,
                                },
                            ),
                        ),
                    },
                ),
                replace: true,
                options: [],
                with_check_option: NoCheckOption,
            },
        ),

Additional context

I would expect Temporary token to be part of RangeVar node but parser still panics so I had to make it part of ViewStmt, very similar to what we had with the As token being part of CreateDomainStmt in #61

psteinroe commented 9 months ago

btw @cvng feel free to add your sample statements do tests/data/statements/valid to also include them in the e2e tests!

cvng commented 9 months ago

btw @cvng feel free to add your sample statements do tests/data/statements/valid to also include them in the e2e tests!

I will do, I find it generally more convenient to debug at the e2e layer