sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.32k stars 398 forks source link

Unable to format SQL: Error: Parse error: Unexpected "$$ DECLARE" #686

Closed divyam234 closed 10 months ago

divyam234 commented 10 months ago

Input data

Which SQL and options did you provide as input?


CREATE
OR REPLACE FUNCTION  generate_uid(size INT) RETURNS TEXT LANGUAGE PLPGSQL AS $$ DECLARE characters TEXT := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

bytes BYTEA := gen_random_bytes(size);

l INT := LENGTH(characters);

i INT := 0;

output TEXT := '';

BEGIN WHILE i < size LOOP output := output || SUBSTR(characters, GET_BYTE(bytes, i) % l + 1, 1);

i := i + 1;

END LOOP;

RETURN output;

END;

$$;
-- ADD SQL HERE

Unable to format SQL: Error: Parse error: Unexpected "$$ DECLARE"

Not able to format function and procedures in vscode extension

nene commented 10 months ago

Simply select PostgreSQL as the dialect to format.

See the FAQ: https://github.com/sql-formatter-org/sql-formatter#parse-error-unexpected--at-line-