squawk icon indicating copy to clipboard operation
squawk copied to clipboard

Squawk Not Detecting Errors in PostgreSQL Function Body

Open salgado-unleashed opened this issue 11 months ago • 2 comments

I'm trying to use squawk to lint a PostgreSQL function, but it seems like the function body is not being checked properly. To test this, I deliberately introduced a syntax error (SELEC instead of SELECT), but squawk did not flag it as an issue. Is there a known limitation with squawk when linting PostgreSQL functions?

  1. Create a SQL file (get_city_by_id.sql) with the following function:
CREATE OR REPLACE FUNCTION world.get_city_by_id(p_city_id BIGINT)
RETURNS TABLE(city_id BIGINT, city_name VARCHAR, country_id INT) AS
$$
BEGIN
    RETURN QUERY
    SELEC city_id, city_name, country_id
    FROM world.city
    WHERE city_id = p_city_id;
END;
$$ LANGUAGE plpgsql;
$ squawk get_city_by_id.sql --verbose
01:31:30 [INFO] no config file found
01:31:30 [INFO] pg version: None
01:31:30 [INFO] excluded rules: []
01:31:30 [INFO] excluded paths: []
01:31:30 [INFO] assume in a transaction: false
01:31:30 [INFO] checking file path: get_city_by_id.sql
Found 0 issues in 1 file 🎉

Does squawk support linting inside plpgsql function bodies? Are there any configuration options required to enable deeper analysis?

salgado-unleashed avatar Feb 18 '25 01:02 salgado-unleashed

yeah we don't currently support linting of function bodies

from a postgres parser perspective, the function body is just a string, in this case a dollar delimited string

but linting function bodies, both sql and plgsql is on the roadmap, we're currently rewriting the parser, so that we can do more fine grained analysis like this.

sbdchd avatar Feb 18 '25 14:02 sbdchd

Hey @sbdchd Thanks for the reply. I hope you guys can get it to work

Thanks a lot =)

salgado-unleashed avatar Mar 05 '25 01:03 salgado-unleashed