supabase-community / postgres_lsp

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

feat: support `DefineStmt` (aggregate) #69

Closed cvng closed 10 months ago

cvng commented 11 months ago

What kind of change does this PR introduce?

feat: support DefineStmt (aggregate): create aggregate ...

What is the current behavior?

Parser panics

What is the new behavior?

pg_query_root: Some(
        DefineStmt(
            DefineStmt {
                kind: ObjectAggregate,
                oldstyle: false,
                defnames: [
                    Node {
                        node: Some(
                            String(
                                String {
                                    sval: "percentile_disc",
                                },
                            ),
                        ),
                    },
                ],
                args: [
                    Node {
                        node: Some(
                            List(
                                List {
                                    items: [
                                        Node {
                                            node: Some(
                                                FunctionParameter(
                                                    FunctionParameter {
                                                        name: "",
                                                        arg_type: Some(
                                                            TypeName {
                                                                names: [
                                                                    Node {
                                                                        node: Some(
                                                                            String(
                                                                                String {
                                                                                    sval: "float8",
                                                                                },
                                                                            ),
                                                                        ),
                                                                    },
                                                                ],
                                                                type_oid: 0,
                                                                setof: false,
                                                                pct_type: false,
                                                                typmods: [],
                                                                typemod: -1,
                                                                array_bounds: [],
                                                                location: 45,
                                                            },
                                                        ),
                                                        mode: FuncParamDefault,
                                                        defexpr: None,
                                                    },
                                                ),
                                            ),
                                        },
                                        Node {
                                            node: Some(
                                                FunctionParameter(
                                                    FunctionParameter {
                                                        name: "",
                                                        arg_type: Some(
                                                            TypeName {
                                                                names: [
                                                                    Node {
                                                                        node: Some(
                                                                            String(
                                                                                String {
                                                                                    sval: "anyelement", // appears once
                                                                                },
                                                                            ),
                                                                        ),
                                                                    },
                                                                ],
                                                                type_oid: 0,
                                                                setof: false,
                                                                pct_type: false,
                                                                typmods: [],
                                                                typemod: -1,
                                                                array_bounds: [],
                                                                location: 61,
                                                            },
                                                        ),
                                                        mode: FuncParamDefault,
                                                        defexpr: None,
                                                    },
                                                ),
                                            ),
                                        },
                                    ],
                                },
                            ),
                        ),
                    },
                    Node {
                        node: Some(
                            Integer(
                                Integer {
                                    ival: 1,
                                },
                            ),
                        ),
                    },
                ],
                definition: [
                    Node {
                        node: Some(
                            DefElem(
                                DefElem {
                                    defnamespace: "",
                                    defname: "sfunc",
                                    arg: Some(
                                        Node {
                                            node: Some(
                                                TypeName(
                                                    TypeName {
                                                        names: [
                                                            Node {
                                                                node: Some(
                                                                    String(
                                                                        String {
                                                                            sval: "ordered_set_transition",
                                                                        },
                                                                    ),
                                                                ),
                                                            },
                                                        ],
                                                        type_oid: 0,
                                                        setof: false,
                                                        pct_type: false,
                                                        typmods: [],
                                                        typemod: -1,
                                                        array_bounds: [],
                                                        location: 99,
                                                    },
                                                ),
                                            ),
                                        },
                                    ),
                                    defaction: DefelemUnspec,
                                    location: 91,
                                },
                            ),
                        ),
                    },
                    Node {
                        node: Some(
                            DefElem(
                                DefElem {
                                    defnamespace: "",
                                    defname: "stype",
                                    arg: Some(
                                        Node {
                                            node: Some(
                                                TypeName(
                                                    TypeName {
                                                        names: [
                                                            Node {
                                                                node: Some(
                                                                    String(
                                                                        String {
                                                                            sval: "internal",
                                                                        },
                                                                    ),
                                                                ),
                                                            },
                                                        ],
                                                        type_oid: 0,
                                                        setof: false,
                                                        pct_type: false,
                                                        typmods: [],
                                                        typemod: -1,
                                                        array_bounds: [],
                                                        location: 147,
                                                    },
                                                ),
                                            ),
                                        },
                                    ),
                                    defaction: DefelemUnspec,
                                    location: 139,
                                },
                            ),
                        ),
                    },
                    Node {
                        node: Some(
                            DefElem(
                                DefElem {
                                    defnamespace: "",
                                    defname: "finalfunc",
                                    arg: Some(
                                        Node {
                                            node: Some(
                                                TypeName(
                                                    TypeName {
                                                        names: [
                                                            Node {
                                                                node: Some(
                                                                    String(
                                                                        String {
                                                                            sval: "percentile_disc_final",
                                                                        },
                                                                    ),
                                                                ),
                                                            },
                                                        ],
                                                        type_oid: 0,
                                                        setof: false,
                                                        pct_type: false,
                                                        typmods: [],
                                                        typemod: -1,
                                                        array_bounds: [],
                                                        location: 185,
                                                    },
                                                ),
                                            ),
                                        },
                                    ),
                                    defaction: DefelemUnspec,
                                    location: 173,
                                },
                            ),
                        ),
                    },
                    Node {
                        node: Some(
                            DefElem(
                                DefElem {
                                    defnamespace: "",
                                    defname: "finalfunc_extra",
                                    arg: None,
                                    defaction: DefelemUnspec,
                                    location: 224,
                                },
                            ),
                        ),
                    },
                ],
                if_not_exists: false,
                replace: true,
            },
        ),
    )

Additional context

Add any other context or screenshots.

psteinroe commented 10 months ago

included in #72 - lmk if we can close this @cvng

cvng commented 10 months ago

included in #72