windowapi.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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-2022, PostgreSQL Global Development Group
  23. *
  24. * src/include/windowapi.h
  25. *
  26. *-------------------------------------------------------------------------
  27. */
  28. #ifndef WINDOWAPI_H
  29. #define WINDOWAPI_H
  30. /* values of "seektype" */
  31. #define WINDOW_SEEK_CURRENT 0
  32. #define WINDOW_SEEK_HEAD 1
  33. #define WINDOW_SEEK_TAIL 2
  34. /* this struct is private in nodeWindowAgg.c */
  35. typedef struct WindowObjectData *WindowObject;
  36. #define PG_WINDOW_OBJECT() ((WindowObject) fcinfo->context)
  37. #define WindowObjectIsValid(winobj) \
  38. ((winobj) != NULL && IsA(winobj, WindowObjectData))
  39. extern void *WinGetPartitionLocalMemory(WindowObject winobj, Size sz);
  40. extern int64 WinGetCurrentPosition(WindowObject winobj);
  41. extern int64 WinGetPartitionRowCount(WindowObject winobj);
  42. extern void WinSetMarkPosition(WindowObject winobj, int64 markpos);
  43. extern bool WinRowsArePeers(WindowObject winobj, int64 pos1, int64 pos2);
  44. extern Datum WinGetFuncArgInPartition(WindowObject winobj, int argno,
  45. int relpos, int seektype, bool set_mark,
  46. bool *isnull, bool *isout);
  47. extern Datum WinGetFuncArgInFrame(WindowObject winobj, int argno,
  48. int relpos, int seektype, bool set_mark,
  49. bool *isnull, bool *isout);
  50. extern Datum WinGetFuncArgCurrent(WindowObject winobj, int argno,
  51. bool *isnull);
  52. #endif /* WINDOWAPI_H */