Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/backend/parser/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ transform_pivot_clause_hook_type transform_pivot_clause_hook = NULL;
/* Hook to transform TSQL unpivot clauses in select stmt */
transform_unpivot_clause_hook_type transform_unpivot_clause_hook = NULL;

/* Hook to transform query if percent operator is present */
transform_percent_clause_hook_type transform_percent_clause_hook = NULL;

static Query *transformOptionalSelectInto(ParseState *pstate, Node *parseTree);
static Query *transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt);
static Query *transformInsertStmt(ParseState *pstate, InsertStmt *stmt);
Expand Down Expand Up @@ -1441,6 +1444,12 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)

qry->commandType = CMD_SELECT;

/* Transform query if percent Operator is present with Top Clause */
if(transform_percent_clause_hook)
{
(*transform_percent_clause_hook)(pstate, stmt);
}

/* Unpack and process TSQL UNPIVOT nodes in stmt->fromClause, if present */
if(transform_unpivot_clause_hook)
{
Expand Down
1 change: 1 addition & 0 deletions src/include/nodes/nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ typedef enum LimitOption
{
LIMIT_OPTION_COUNT, /* FETCH FIRST... ONLY */
LIMIT_OPTION_WITH_TIES, /* FETCH FIRST... WITH TIES */
LIMIT_OPTION_PERCENT, /* FETCH FIRST... PERCENT */
} LimitOption;

#endif /* NODES_H */
5 changes: 5 additions & 0 deletions src/include/nodes/parsenodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,7 @@ typedef struct InsertStmt
OverridingKind override; /* OVERRIDING clause */
Node *execStmt; /* for INSERT ... EXECUTE */
Node *limitCount; /* used by INSERT TOP in T-SQL*/
LimitOption limitOption; /* limit type */
} InsertStmt;

/* ----------------------
Expand All @@ -2068,6 +2069,7 @@ typedef struct DeleteStmt
List *returningList; /* list of expressions to return */
WithClause *withClause; /* WITH clause */
Node *limitCount; /* used with DELETE TOP in T-SQL */
LimitOption limitOption; /* limit type */
} DeleteStmt;

/* ----------------------
Expand All @@ -2084,6 +2086,7 @@ typedef struct UpdateStmt
List *returningList; /* list of expressions to return */
WithClause *withClause; /* WITH clause */
Node *limitCount; /* used with UPDATE TOP in T-SQL */
LimitOption limitOption; /* limit type */
} UpdateStmt;

/* ----------------------
Expand Down Expand Up @@ -2177,9 +2180,11 @@ typedef struct SelectStmt
List *value_col_strlist;
ColumnRef *pivotCol;
Node *aggFunc;

} SelectStmt;



/* ----------------------
* Set Operation node for post-analysis query trees
*
Expand Down
4 changes: 4 additions & 0 deletions src/include/parser/analyze.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ extern PGDLLEXPORT transform_pivot_clause_hook_type transform_pivot_clause_hook;
typedef void (*transform_unpivot_clause_hook_type)(ParseState *pstate, SelectStmt *stmt);
extern PGDLLEXPORT transform_unpivot_clause_hook_type transform_unpivot_clause_hook;

/* Hook to transform query if percent operator is present */
typedef void (*transform_percent_clause_hook_type)(ParseState *pstate, SelectStmt *stmt);
extern PGDLLEXPORT transform_percent_clause_hook_type transform_percent_clause_hook;

extern Query *parse_analyze_fixedparams(RawStmt *parseTree, const char *sourceText,
const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv);
extern Query *parse_analyze(RawStmt *parseTree, const char *sourceText,
Expand Down