Open
Description
The DECLARE
statement in PL/pgSQL is similar to the one in PL/SQL and is used to declare variables: https://www.postgresql.org/docs/current/plpgsql-declarations.html
Test case in PostgreSQL:
-- Current behaviour
CREATE FUNCTION less_than(a text, b text) RETURNS boolean AS $$
DECLARE
local_a text := a;
local_b text := b;
BEGIN
RETURN local_a < local_b;
END;
$$ LANGUAGE plpgsql;
-- Expected behaviour
CREATE FUNCTION less_than(a text, b text) RETURNS boolean AS $$
DECLARE
local_a text := a;
local_b text := b;
BEGIN
RETURN local_a < local_b;
END;
$$ LANGUAGE plpgsql;
However, there is also a DECLARE
statement that creates a cursor: https://www.postgresql.org/docs/12/sql-declare.html
-- Current behaviour
DECLARE
liahona
CURSOR FOR
SELECT *
FROM films;
-- Expected
DECLARE
liahona
CURSOR FOR
SELECT *
FROM films;
I think sqlind-beginning-of-block
probably needs to handle the PostgreSQL case:
emacs-sql-indent/sql-indent.el
Lines 956 to 957 in 56be397
However, for the cursor use-case, I think that sqlind-maybe-declare-statement
needs to understand if it’s in-begin-block
and do something special, especially in order to recognize and indent the embedded SELECT
or VALUES
statement.