joe-re / sql-language-server

SQL Language Server
MIT License
661 stars 63 forks source link

Failure to parse valid PostgreSQL statements #186

Open bennieswart opened 1 year ago

bennieswart commented 1 year ago

This is probably a very similar issue to https://github.com/joe-re/sql-language-server/issues/129 in that it simply requires extension of the parser.

The code I'm hacking on:

CREATE OR REPLACE FUNCTION api._cuidin(cstring) RETURNS api._cuid AS 'textin' LANGUAGE internal STABLE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION api._cuidout(api._cuid) RETURNS cstring AS 'textout' LANGUAGE internal STABLE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION api._cuidrecv(internal) RETURNS api._cuid AS 'textrecv' LANGUAGE internal STABLE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION api._cuidsend(api._cuid) RETURNS bytea AS 'textsend' LANGUAGE internal STABLE PARALLEL SAFE;
CREATE TYPE api._cuid (
    INPUT = api._cuidin,
    OUTPUT = api._cuidout,
    RECEIVE = api._cuidrecv,
    SEND = api._cuidsend
);

CREATE OR REPLACE FUNCTION api._cuid_text_eq(uid1 api._cuid, uid2 text) RETURNS bool AS $$
BEGIN
    RAISE NOTICE 'custom equals';
    RETURN uid1::text = uid2;
END;
$$ LANGUAGE plpgsql;

CREATE OPERATOR = (
    FUNCTION = api._cuid_text_eq,
    LEFTARG = api._cuid,
    RIGHTARG = text
);
rockerBOO commented 1 year ago

Additionally, there are these:

CREATE TYPE kind as ENUM("a", "b");
-- Expected "--", "/*", "INDEX", or [ \t\n\r] but "T" found.
DROP TYPE kind;
-- Expected "$", "(", "--", "/*", "ALTER", "CREATE TABLE", "CREATE", "DELETE", "INSERT", "REPLACE", "SELECT", "UPDATE", "WITH", "return", or [ \t\n\r] but "D" found.

https://www.postgresql.org/docs/current/sql-droptype.html https://www.postgresql.org/docs/current/datatype-enum.html

Thanks!

jasonpanosso commented 11 months ago

Same issue with this:

CREATE EXTENSION IF NOT EXISTS "pg_net" WITH SCHEMA "extensions";
-- Expected "--", "/*", "INDEX", or [ \t\n\r] but "E" found.
CREATE OR REPLACE FUNCTION some_func()
-- Expected "--", "/*", "INDEX", or [ \t\n\r] but "O" found.

https://www.postgresql.org/docs/current/sql-createextension.html https://www.postgresql.org/docs/current/sql-createfunction.html

Appreciate the lsp! Works great when not using certain statements

joe-re commented 10 months ago

Now we support create/drop type from v1.7.0.

raxod502 commented 3 days ago

I'm seeing this simple foreign key relation fail to parse:

CREATE TABLE cities (
        name     varchar(80) primary key,
        location point
);

CREATE TABLE weather (
        city      varchar(80) references cities(name),
        temp_lo   int,
        temp_hi   int,
        prcp      real,
        date      date
);

image

I'm pretty sure it's valid code because I just copied it directly from the PostgreSQL manual here: https://www.postgresql.org/docs/current/tutorial-fk.html