Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IDENTITY() function in SELECT-INTO #166

Merged
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/commands/createas.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "parser/parse_clause.h"
#include "parser/parser.h"
#include "rewrite/rewriteHandler.h"
#include "storage/smgr.h"
#include "tcop/tcopprot.h"
#include "tcop/utility.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/rls.h"
#include "utils/snapmgr.h"

bbfSelectIntoAddIdentity_hook_type bbfSelectIntoAddIdentity_hook = NULL;

typedef struct
{
DestReceiver pub; /* publicly-known function pointers */
Expand Down Expand Up @@ -110,6 +114,11 @@ create_ctas_internal(List *attrList, IntoClause *into)
create->if_not_exists = false;
create->accessMethod = into->accessMethod;

if (sql_dialect == SQL_DIALECT_TSQL)
{
if(into->identityName && bbfSelectIntoAddIdentity_hook)
(*bbfSelectIntoAddIdentity_hook)(into, create->tableElts);
}
/*
* Create the relation. (This will error out if there's an existing view,
* so we don't need more code to complain if "replace" is false.)
Expand Down
11 changes: 9 additions & 2 deletions src/backend/tcop/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
/* Hook for plugins to get control in ProcessUtility() */
ProcessUtility_hook_type ProcessUtility_hook = NULL;
bbfCustomProcessUtility_hook_type bbfCustomProcessUtility_hook = NULL;
bbfSelectIntoUtility_hook_type bbfSelectIntoUtility_hook = NULL;

/* local function declarations */
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree);
Expand Down Expand Up @@ -1681,8 +1682,14 @@ ProcessUtilitySlow(ParseState *pstate,
break;

case T_CreateTableAsStmt:
address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
params, queryEnv, qc);
{
if(sql_dialect == SQL_DIALECT_TSQL && bbfSelectIntoUtility_hook)
(*bbfSelectIntoUtility_hook)(pstate, pstmt, queryString, NULL, params, qc);
else{
address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
params, queryEnv, qc);
}
}
break;

case T_RefreshMatViewStmt:
Expand Down
2 changes: 2 additions & 0 deletions src/include/nodes/primnodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ typedef struct IntoClause
char *tableSpaceName; /* table space to use, or NULL */
Node *viewQuery; /* materialized view's SELECT query */
bool skipData; /* true for WITH NO DATA */
char *identityName; /* resname for Identity Column*/
char *identityType; /* pg type for Identity Column*/
} IntoClause;


Expand Down
6 changes: 6 additions & 0 deletions src/include/tcop/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,11 @@ extern bool CommandIsReadOnly(PlannedStmt *pstmt);
typedef bool (*bbfCustomProcessUtility_hook_type)(struct ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context,
ParamListInfo params, QueryCompletion *qc);
extern PGDLLIMPORT bbfCustomProcessUtility_hook_type bbfCustomProcessUtility_hook;
typedef void (*bbfSelectIntoUtility_hook_type)(struct ParseState *pstate, PlannedStmt *pstmt, const char *queryString, QueryEnvironment *queryEnv,
ParamListInfo params, QueryCompletion *qc);
extern PGDLLIMPORT bbfSelectIntoUtility_hook_type bbfSelectIntoUtility_hook;

typedef void (*bbfSelectIntoAddIdentity_hook_type)(IntoClause *into, List *tableElts);
extern PGDLLIMPORT bbfSelectIntoAddIdentity_hook_type bbfSelectIntoAddIdentity_hook;

#endif /* UTILITY_H */