libpg_query icon indicating copy to clipboard operation
libpg_query copied to clipboard

btree index parser err

Open Hanko2024 opened this issue 2 years ago • 2 comments

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 []

Hanko2024 avatar Aug 28 '23 09:08 Hanko2024

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

lelit avatar Sep 01 '23 11:09 lelit

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

Hanko2024 avatar Sep 06 '23 04:09 Hanko2024

Per the earlier comment, pg_query_parse_plpgsql is not intended to parse arbitrary SQL (it parses PL/pgSQL function definitions), thus closing this as won't fix.

lfittl avatar Apr 02 '25 05:04 lfittl