Search code examples
postgresqlvisual-studio-codesyntax-highlighting

Better syntax highlighting for PostgreSQL in VS Code


This code:

CREATE OR REPLACE TRIGGER some_trigger
    BEFORE INSERT OR DELETE OR UPDATE 
    ON some.table
    FOR EACH ROW
    EXECUTE FUNCTION some_trigger_function();

is highlighted like this:

PostgreSQL syntax highlighting

See the yellow instead of blue REPLACE or the white instead of blue FOR EACH? I suppose this is some standard sql syntax highlighting. But for PostgreSQL this is good.

I tried installing extensions like "Better PostgreSQL Syntax" or "PostgreSQL" but nothing changed.

How can I get good syntax highlighting for PostgreSQL in VS code?


Solution

  • The extension PostgreSQL by Chris Kolkman did the trick for me in the end.

    In its feature list under "Programming Languages" there are file extension *.pgsql and *.psql listed.

    What I did then:

    • Disable the extensions Better PostgreSQL Syntax, SQLTools and the dependent PostgreSQL driver
    • Install PostgreSQL by Chris Kolkman
    • Rename *.sql files to *.pgsql
    • Reload the window

    After that VS Code recognised the new file extensions and used the correct syntax highlighting (Language Mode "Postgres").