-
Notifications
You must be signed in to change notification settings - Fork 6
/
function.go
51 lines (46 loc) · 2.3 KB
/
function.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package pqt
const (
// FunctionBehaviourVolatile indicates that the function value can change even within a single table scan,
// so no optimizations can be made.
// Relatively few database functions are volatile in this sense; some examples are random(), currval(), timeofday().
// But note that any function that has side-effects must be classified volatile, even if its result is quite predictable,
// to prevent calls from being optimized away; an example is setval().
FunctionBehaviourVolatile FunctionBehaviour = iota
// FunctionBehaviourImmutable indicates that the function cannot modify the database and always returns the same result when given the same argument values;
// that is, it does not do database lookups or otherwise use information not directly present in its argument list.
// If this option is given, any call of the function with all-constant arguments can be immediately replaced with the function value.
FunctionBehaviourImmutable
// FunctionBehaviourStable indicates that the function cannot modify the database,
// and that within a single table scan it will consistently return the same result for the same argument values,
// but that its result could change across SQL statements.
// This is the appropriate selection for functions whose results depend on database lookups,
// parameter variables (such as the current time zone), etc.
// (It is inappropriate for AFTER triggers that wish to query rows modified by the current command.)
// Also note that the current_timestamp family of functions qualify as stable, since their values do not change within a transaction.
FunctionBehaviourStable
)
// FunctionBehaviour is a function behaviour, it can be volatile, immutable or stable.
type FunctionBehaviour int
// Function describes database function.
type Function struct {
Name string
BuiltIn bool
Type Type
Body string
Behaviour FunctionBehaviour
Args []*FunctionArg
}
// FunctionArg is a function argument, it is used to describe function signature.
type FunctionArg struct {
Name string
Type Type
}
// FunctionNow is a helper function that creates now() function.
// Now() returns current timestamp with time zone (abbreviated as timestamptz).
func FunctionNow() *Function {
return &Function{
Name: "now",
BuiltIn: true,
Type: TypeTimestampTZ(),
}
}