fix create as in rewritehandler
This reverts commit 41b5cbf3cdd607313b1dc6b9dc6b78ab2f7b1a3b.
This commit is contained in:
@ -35,6 +35,7 @@
|
||||
#include "parser/parsetree.h"
|
||||
#include "parser/parse_merge.h"
|
||||
#include "parser/parse_hint.h"
|
||||
#include "parser/parse_type.h"
|
||||
#include "rewrite/rewriteDefine.h"
|
||||
#include "rewrite/rewriteHandler.h"
|
||||
#include "rewrite/rewriteManip.h"
|
||||
@ -4507,6 +4508,21 @@ static bool findAttrByName(const char* attributeName, List* tableElts, int maxle
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* for create table as in B foramt, add type's oid and typemod in tableElts
|
||||
*/
|
||||
static void addInitAttrType(List* tableElts)
|
||||
{
|
||||
ListCell* lc = NULL;
|
||||
|
||||
foreach (lc, tableElts) {
|
||||
Node* node = (Node*)lfirst(lc);
|
||||
if (IsA(node, ColumnDef)) {
|
||||
ColumnDef* def = (ColumnDef*)node;
|
||||
typenameTypeIdAndMod(NULL, def->typname, &def->typname->typeOid, &def->typname->typemod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* GetCreateTableStmt(Query* parsetree, CreateTableAsStmt* stmt)
|
||||
{
|
||||
@ -4517,8 +4533,10 @@ char* GetCreateTableStmt(Query* parsetree, CreateTableAsStmt* stmt)
|
||||
IntoClause* into = stmt->into;
|
||||
List* tableElts = NIL;
|
||||
|
||||
if (u_sess->attr.attr_sql.sql_compatibility == B_FORMAT)
|
||||
if (u_sess->attr.attr_sql.sql_compatibility == B_FORMAT) {
|
||||
tableElts = stmt->into->tableElts;
|
||||
addInitAttrType(tableElts);
|
||||
}
|
||||
int initlen = list_length(tableElts);
|
||||
|
||||
/* Obtain the target list of new table */
|
||||
@ -4674,8 +4692,7 @@ char* GetCreateTableStmt(Query* parsetree, CreateTableAsStmt* stmt)
|
||||
|
||||
StringInfo cquery = makeStringInfo();
|
||||
|
||||
if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT || initlen <= 0)
|
||||
deparse_query(parsetree, cquery, NIL, false, false);
|
||||
deparse_query(parsetree, cquery, NIL, false, false);
|
||||
|
||||
return cquery->data;
|
||||
}
|
||||
|
@ -218,5 +218,17 @@ select * from tb_unique;
|
||||
1 | 1
|
||||
(3 rows)
|
||||
|
||||
--fixbug
|
||||
drop table if exists t_base;
|
||||
create table t_base(col1 int, col2 int, col3 int);
|
||||
insert into t_base values(1,2,3),(11,22,33);
|
||||
create table ttt3(col int) as select * from t_base;
|
||||
select * from ttt3;
|
||||
col | col1 | col2 | col3
|
||||
-----+------+------+------
|
||||
| 1 | 2 | 3
|
||||
| 11 | 22 | 33
|
||||
(2 rows)
|
||||
|
||||
\c postgres
|
||||
drop database b_createas;
|
||||
|
@ -107,5 +107,12 @@ insert into tb_unique values(1,1) ON DUPLICATE KEY UPDATE a = 1, b = 1;
|
||||
select * from tb_primary;
|
||||
select * from tb_unique;
|
||||
|
||||
--fixbug
|
||||
drop table if exists t_base;
|
||||
create table t_base(col1 int, col2 int, col3 int);
|
||||
insert into t_base values(1,2,3),(11,22,33);
|
||||
create table ttt3(col int) as select * from t_base;
|
||||
select * from ttt3;
|
||||
|
||||
\c postgres
|
||||
drop database b_createas;
|
||||
|
Reference in New Issue
Block a user