PostgreSQL Source Code  git master
windowapi.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * windowapi.h
4  * API for window functions to extract data from their window
5  *
6  * A window function does not receive its arguments in the normal way
7  * (and therefore the concept of strictness is irrelevant). Instead it
8  * receives a "WindowObject", which it can fetch with PG_WINDOW_OBJECT()
9  * (note V1 calling convention must be used). Correct call context can
10  * be tested with WindowObjectIsValid(). Although argument values are
11  * not passed, the call is correctly set up so that PG_NARGS() can be
12  * used and argument type information can be obtained with
13  * get_fn_expr_argtype(), get_fn_expr_arg_stable(), etc.
14  *
15  * Operations on the WindowObject allow the window function to find out
16  * the current row number, total number of rows in the partition, etc
17  * and to evaluate its argument expression(s) at various rows in the
18  * window partition. See the header comments for each WindowObject API
19  * function in nodeWindowAgg.c for details.
20  *
21  *
22  * Portions Copyright (c) 2000-2024, PostgreSQL Global Development Group
23  *
24  * src/include/windowapi.h
25  *
26  *-------------------------------------------------------------------------
27  */
28 #ifndef WINDOWAPI_H
29 #define WINDOWAPI_H
30 
31 /* values of "seektype" */
32 #define WINDOW_SEEK_CURRENT 0
33 #define WINDOW_SEEK_HEAD 1
34 #define WINDOW_SEEK_TAIL 2
35 
36 /* this struct is private in nodeWindowAgg.c */
38 
39 #define PG_WINDOW_OBJECT() ((WindowObject) fcinfo->context)
40 
41 #define WindowObjectIsValid(winobj) \
42  ((winobj) != NULL && IsA(winobj, WindowObjectData))
43 
44 extern void *WinGetPartitionLocalMemory(WindowObject winobj, Size sz);
45 
46 extern int64 WinGetCurrentPosition(WindowObject winobj);
47 extern int64 WinGetPartitionRowCount(WindowObject winobj);
48 
49 extern void WinSetMarkPosition(WindowObject winobj, int64 markpos);
50 
51 extern bool WinRowsArePeers(WindowObject winobj, int64 pos1, int64 pos2);
52 
53 extern Datum WinGetFuncArgInPartition(WindowObject winobj, int argno,
54  int relpos, int seektype, bool set_mark,
55  bool *isnull, bool *isout);
56 
57 extern Datum WinGetFuncArgInFrame(WindowObject winobj, int argno,
58  int relpos, int seektype, bool set_mark,
59  bool *isnull, bool *isout);
60 
61 extern Datum WinGetFuncArgCurrent(WindowObject winobj, int argno,
62  bool *isnull);
63 
64 #endif /* WINDOWAPI_H */
size_t Size
Definition: c.h:605
uintptr_t Datum
Definition: postgres.h:64
Datum WinGetFuncArgInPartition(WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool *isnull, bool *isout)
Datum WinGetFuncArgInFrame(WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool *isnull, bool *isout)
int64 WinGetCurrentPosition(WindowObject winobj)
bool WinRowsArePeers(WindowObject winobj, int64 pos1, int64 pos2)
void WinSetMarkPosition(WindowObject winobj, int64 markpos)
void * WinGetPartitionLocalMemory(WindowObject winobj, Size sz)
Datum WinGetFuncArgCurrent(WindowObject winobj, int argno, bool *isnull)
int64 WinGetPartitionRowCount(WindowObject winobj)
struct WindowObjectData * WindowObject
Definition: windowapi.h:37