pg_ivm/ruleutils.c
Yugo Nagata 6faf0b3baa
Support min/max aggregates (#18)
In order to re-calculate min/max values for groups where the min
or max value is deleted, we need the view query definition in string
form. However, pg_get_viewdef cannot be used for this purpose because
IMMV's defenition is in pg_ivm_immv but not pg_rewrite.  Therefore,
we have to convert query definition in pg_ivm_immv to query
definition string. We can use pg_get_querydef in PG15, but we cannot
in PG14 or earlier, so we use codes in ruleutil.c copied from PG13
or PG14 depending versions.
2022-07-25 13:11:33 +09:00

59 lines
1.5 KiB
C

/*-------------------------------------------------------------------------
*
* ruleutils.c
* incremental view maintenance extension
* Routines for convert stored expressions/querytrees back to
* source text
*
* Portions Copyright (c) 2022, IVM Development Group
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#if defined(PG_VERSION_NUM) && (PG_VERSION_NUM >= 150000)
#include "utils/ruleutils.h"
#elif defined(PG_VERSION_NUM) && (PG_VERSION_NUM >= 140000)
#include "ruleutils_14.c"
#else
#include "ruleutils_13.c"
#endif
#include "pg_ivm.h"
/* Standard conversion of a "bool pretty" option to detailed flags */
#define GET_PRETTY_FLAGS(pretty) \
((pretty) ? (PRETTYFLAG_PAREN | PRETTYFLAG_INDENT | PRETTYFLAG_SCHEMA) \
: PRETTYFLAG_INDENT)
/* ----------
* pg_get_querydef
*
* Public entry point to deparse one query parsetree.
* The pretty flags are determined by GET_PRETTY_FLAGS(pretty).
*
* The result is a palloc'd C string.
* ----------
*/
char *
pg_ivm_get_querydef(Query *query, bool pretty)
{
#if defined(PG_VERSION_NUM) && (PG_VERSION_NUM >= 150000)
return pg_get_querydef(query, pretty);
#else
StringInfoData buf;
int prettyFlags;
prettyFlags = GET_PRETTY_FLAGS(pretty);
initStringInfo(&buf);
get_query_def(query, &buf, NIL, NULL, true,
prettyFlags, WRAP_COLUMN_DEFAULT, 0);
return buf.data;
#endif
}