@@ -3,7 +3,12 @@ open Rezoom.SQL.Compiler
33open Rezoom.SQL .Compiler .FunctionDeclarations
44
55let functions =
6- [| // math https://www.postgresql.org/docs/9.6/static/functions-math.html
6+ [| proc " lastval" [] integral
7+ func " nullif" [ a'; a' ] ( nullable a')
8+ func " greatest" [ infect a'; infect ( vararg a') ] a'
9+ func " least" [ infect a'; infect ( vararg a') ] a'
10+
11+ // math https://www.postgresql.org/docs/9.6/static/functions-math.html
712 func " cbrt" [ infect num ] float64
813 func " sqrt" [ infect num ] float64
914 func " ceil" [ infect ( numeric a') ] a'
@@ -101,10 +106,72 @@ let functions =
101106 func " set_bit" [ infect binary; infect int32; infect int32 ] binary
102107 func " set_byte" [ infect binary; infect int32; infect int32 ] binary
103108
109+ // formatting functions https://www.postgresql.org/docs/current/static/functions-formatting.html
110+ func " to_char" [ infect scalar ] string
111+ // func "to_date" [ infect string; infect string ] date // we don't have a date type
112+ func " to_number" [ infect string; infect string ] num
113+ func " to_timestamp" [ infect scalar; optional ( infect string) ] datetimey
114+
115+ // date/time functions https://www.postgresql.org/docs/current/static/functions-datetime.html
116+ // func "age" [ infect datetimey; infect datetimey ] interval // we don't have interval types
117+ proc " clock_timestamp" [] datetimey
118+ // TODO: translate without parens
119+ // proc "current_timestamp" [] datetimey
120+ func " date_part" [ infect string; infect datetimey ] float64
121+ func " date_trunc" [ infect string; infect datetimey ] datetimey
122+ // TODO: handle funky syntax extract(hour from timestamp '...')
123+ // func "extract" [ string; datetimey ] float64
124+ func " isfinite" [ infect datetimey ] boolean
125+ // no justify_whatever since we don't have intervals
126+ func " make_timestamp"
127+ ( List.map infect [ int32; int32; int32; int32; int32; float64 ]) datetimey
128+ func " make_timestamptz"
129+ ( List.map infect [ int32; int32; int32; int32; int32; float64; optional string ]) datetimey
130+ proc " now" [] datetimey
131+ proc " statement_timestamp" [] datetimey
132+ proc " timeofday" [] string
133+ proc " transaction_timestamp" [] datetimey
134+ func " to_timestamp" [ infect float64 ] datetimey
135+
136+ // no enum, array, range, or geometric functions because we can't handle those types
137+
138+ // no full text search or xml functions yet -- might want to handle these later
139+ // https://www.postgresql.org/docs/current/static/functions-textsearch.html
140+ // https://www.postgresql.org/docs/current/static/functions-xml.html
141+ // https://www.postgresql.org/docs/current/static/functions-json.html
142+
104143 // aggregate functions
105144 aggregate " avg" [ numeric a' ] ( nullable a')
106145 aggregateW " count" [ scalar ] int64
107146 aggregate " max" [ a' ] ( nullable a')
108147 aggregate " min" [ a' ] ( nullable a')
109148 aggregate " sum" [ numeric a' ] a'
149+ aggregate " bit_and" [ intish a' ] ( nullable a')
150+ aggregate " bit_or" [ intish a' ] ( nullable a')
151+ aggregate " bool_and" [ boolean ] boolean
152+ aggregate " bool_or" [ boolean ] boolean
153+ aggregate " every" [ boolean ] boolean
154+ aggregate " json_agg" [ scalar ] string // pretend json is a string...
155+ aggregate " json_object_agg" [ string; scalar ] string
156+ aggregate " string_agg" [ stringish a'; stringish a' ] a'
157+ // statistical aggregate functions
158+ aggregate " corr" [ float64; float64 ] ( nullable float64)
159+ aggregate " covar_pop" [ float64; float64 ] ( nullable float64)
160+ aggregate " covar_samp" [ float64; float64 ] ( nullable float64)
161+ aggregate " regr_avgx" [ float64; float64 ] ( nullable float64)
162+ aggregate " regr_avgy" [ float64; float64 ] ( nullable float64)
163+ aggregate " regr_count" [ float64; float64 ] int64
164+ aggregate " regr_intercept" [ float64; float64 ] ( nullable float64)
165+ aggregate " regr_r2" [ float64; float64 ] ( nullable float64)
166+ aggregate " regr_slope" [ float64; float64 ] ( nullable float64)
167+ aggregate " regr_sxx" [ float64; float64 ] float64
168+ aggregate " regr_sxy" [ float64; float64 ] float64
169+ aggregate " regr_syy" [ float64; float64 ] float64
170+ aggregate " stddev" [ numeric a' ] ( nullable a')
171+ aggregate " stddev_pop" [ numeric a' ] ( nullable a')
172+ aggregate " stddev_samp" [ numeric a' ] ( nullable a')
173+ aggregate " variance" [ numeric a' ] ( nullable a')
174+ aggregate " var_pop" [ numeric a' ] ( nullable a')
175+ aggregate " var_samp" [ numeric a' ] ( nullable a')
176+ aggregate " grouping" [ scalar; vararg scalar ] int32
110177 |] |> DefaultFunctions.extendedBy
0 commit comments