## Syntax highlighting for (Postgres) SQL scripts.

syntax sql "\.sql$"
comment "-- "

# Types.
color green "\<(integer|int[248]|(big|small)?(int|serial)|decimal|numeric|real|double precision)\>"
color green "\<(bit( varying)?|boolean|bytea|enum|money|tsquery|tsvector|uuid|xml)\>"
color green "\<(char|varchar|character( varying)?|text|cidr|inet|macaddr8?)\>"
color green "\<(date|interval|time(stamp)?( with(out)? time zone)?)\>"
color green "\<(box|circle|line|lseg|path|point|polygon)\>"
color green "\<(date|int[48]|num|ts|tstz)range\>"

# SQL keywords.
color lagoon "\<(ABORT|AGGREGATE|ALL|ALTER|ANALYZE|AND|ANY|AS|BEGIN|BETWEEN|CAST|CHECKPOINT)\>"
color lagoon "\<(CLOSE|CLUSTER|COLLATION|COMMENT|COMMIT|CONSTRAINTS?|CONVERSION|COPY|CREATE)\>"
color lagoon "\<(DATABASE|DEALLOCATE|DECLARE|DEFAULT|DELETE|DISCARD|DISTINCT|DO|DOMAIN|DROP)\>"
color lagoon "\<(END|EXECUTE|EXISTS|EXPLAIN|EXTENSION|FETCH|FOREIGN (DATA WRAPPER|SCHEMA|TABLE))\>"
color lagoon "\<(FROM|FUNCTION|GRANT|GROUP( BY)?|HAVING|IN|INDEX|INSERT|INTO)\>"
color lagoon "\<(NATURAL )?(INNER |OUTER |CROSS |(LEFT|RIGHT|FULL)( OUTER)? )?JOIN\>"
color lagoon "\<((PRIMARY|FOREIGN) KEY|LANGUAGE|LOAD|LOCK|MOVE|NOT|NOTIFY)\>"
color lagoon "\<(ON|ONLY|OPERATOR( CLASS| FAMILY)?|OR|ORDER BY|PREPARED?|PRIVILEGES)\>"
color lagoon "\<(RELEASE|RESET|RETURNING|REVOKE|ROLE|ROLLBACK|RULE|SAVEPOINT|SCHEMA)\>"
color lagoon "\<(SELECT|SEQUENCE|SERVER|SESSION AUTHORIZATION|SET|SHOW|START|SYSTEM)\>"
color lagoon "\<(TABLE(SPACE)?|TEXT SEARCH (CONFIGURATION|DICTIONARY|PARSER|TEMPLATE))\>"
color lagoon "\<(TO|TRANSACTION|(EVENT )?TRIGGER|TYPE|UPDATE|USER( MAPPING)?|USING)\>"
color lagoon "\<(VACUUM|VALUES|((REFRESH )?MATERIALIZED )?VIEW|WHERE|WITH)\>"

# Flow control.
color brightyellow "\<(CASE|WHEN|IF|THEN|ELSE|ELSE?IF|LOOP|CONTINUE|EXIT)\>"
color brightyellow "\<(FOR|FOREACH|IN|WHILE|END (CASE|IF|LOOP))\>"
color magenta "\<(RAISE|EXCEPTION|NOTICE|RETURN)\>"

# Quoted identifiers.  (First scare-color all, then uncolor what is valid.)
color ,red ""[^"]+""
color normal ""[[:alpha:]_][[:alnum:]_$]*""

# Strings.
color green "'([^']|\\')*'"

# Trailing whitespace.
color ,green "[[:space:]]+$"

# Comments.
color red "--.*"
color brightblue "//.*"
color brightblue start="/\*" end="\*/"

# PostgreSQL default schemas.
color brightred "\<(pg_catalog|public)\>"

# PostgreSQL PLs.
color brightblue "\<pl(java|perlu?|pgsql|py|pythonu?|r|ruby|scheme|sh|tcl)\>"
