pganalyze / libpg_query

C library for accessing the PostgreSQL parser outside of the server environment
BSD 3-Clause "New" or "Revised" License
1.16k stars 170 forks source link

btree index parser err #208

Open liuhangyu opened 1 year ago

liuhangyu commented 1 year ago

sql:

CREATE UNIQUE INDEX t_role_tcd_unique_index ON dino.t_role USING btree (tenant_id, \ code,(CASE WHEN (del_flag = 1) THEN id ELSE (del_flag)::bigint END)); cannot be parsed

int main() { PgQueryPlpgsqlParseResult result;

//目前无法解析的sql
result =
    pg_query_parse_plpgsql("CREATE UNIQUE INDEX t_role_tcd_unique_index ON dino.t_role USING btree (tenant_id, \

code,(CASE WHEN (del_flag = 1) THEN id ELSE (del_flag)::bigint END));"); if (result.error) { printf("error: %s at %d\n", result.error->message, result.error->cursorpos); } else { printf("%s\n", result.plpgsql_funcs); }

pg_query_free_plpgsql_parse_result(result);

return 0;

}

result.plpgsql_funcs output as []

lelit commented 1 year ago

Why are you using pg_query_parse_plpgsql() there instead of pg_query_parse()? That statement is “plain” SQL, isn't it?

liuhangyu commented 1 year ago

Using the pg_query_parse function works fine, but I'm not sure if there is a bug in pg_query_parse_plpgsql