package format // keywords are SQL / PL/pgSQL words the formatter may re-case via KeywordCase. // Type-name words are deliberately excluded (see typeNames) so the house style // can keep types lowercase while keywords are uppercased. var keywords = words(` add after all alter analyze and any array as asc atomic begin between by called cascade case cast check close coalesce collate column commit concurrently constraint create cross cube current_date current_time current_timestamp current_user cursor declare default deferrable definer delete desc distinct do drop each else elsif end except exception execute exists external fetch filter first for foreach foreign from full function get grant group grouping having if ilike immutable in index inner inout insert intersect into into invoker is join key language last leakproof left like limit localtime localtimestamp loop materialized natural new next no not nothing notify null nulls of off offset old on only open or order out outer over overriding parallel partition perform precision primary procedure raise references refresh rename replace reset restrict return returning returns revoke right rollback row rows safe schema secdef security select sequence set setof some stable stacked strict table temp temporary then to transaction trigger truncate union unique unsafe update using vacuum values variadic view volatile when where while window with within `) // typeNames are built-in/common type words kept lowercase by the house style. var typeNames = words(` bigint bigserial bit bool boolean box bytea char character cidr circle citext date daterange decimal double float float4 float8 hstore inet int int2 int4 int8 integer interval json jsonb line lseg macaddr macaddr8 money numeric oid path pg_lsn point polygon real serial serial2 serial4 serial8 smallint smallserial text time timestamp timestamptz timetz tsquery tsrange tstzrange tsvector uuid varbit varchar xml `) func words(s string) map[string]bool { m := make(map[string]bool) w := "" for _, r := range s { if r == ' ' || r == '\n' || r == '\t' || r == '\r' { if w != "" { m[w] = true w = "" } continue } w += string(r) } if w != "" { m[w] = true } return m } // builtinFunctions are built-in function names controlled by BuiltinCase. var builtinFunctions = words(` abs age array_agg array_length array_lower array_ndims array_upper bit_length btrim cardinality ceil ceiling char_length character_length chr clock_timestamp coalesce concat concat_ws count currval decode div encode exp extract floor generate_series greatest initcap jsonb_agg jsonb_object_agg justify_days justify_hours justify_interval lastval least length lower lpad ltrim max md5 min mod now nullif overlay pg_sleep position power quote_ident quote_literal random regexp_match regexp_matches regexp_replace replace reverse round rpad rtrim setval split_part sqrt string_agg strpos substr substring sum to_char to_date to_json to_jsonb to_number to_timestamp to_tsvector translate trim trunc unnest upper width_bucket `) func isKeyword(lower string) bool { return keywords[lower] } func isTypeName(lower string) bool { return typeNames[lower] } func isBuiltinFunc(lower string) bool { return builtinFunctions[lower] }