[patch] pg_attribute.attndims turns to 0 when 'create table like/as'
As reported in [1]/messages/by-id/20150707072942.1186.98151@wrigleys.postgresql.org, pg_attribute.attndims turns to 0 when 'create table
like/as'.
The patch attached is to fix it.
Best Regards,
Alexey
[1]: /messages/by-id/20150707072942.1186.98151@wrigleys.postgresql.org
/messages/by-id/20150707072942.1186.98151@wrigleys.postgresql.org
Attachments:
create_table_like_populate_ndims.patchtext/x-patch; name=create_table_like_populate_ndims.patchDownload
diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c
new file mode 100644
index 1bd2599..8fff3d2
*** a/src/backend/nodes/makefuncs.c
--- b/src/backend/nodes/makefuncs.c
*************** makeTypeNameFromOid(Oid typeOid, int32 t
*** 475,480 ****
--- 475,498 ----
n->typeOid = typeOid;
n->typemod = typmod;
n->location = -1;
+
+ return n;
+ }
+
+ /*
+ * makeTypeNameFromOid -
+ * build a TypeName node to represent a type already known by OID/typmod/ndims
+ */
+ TypeName *
+ makeTypeNameWithNdimsFromOid(Oid typeOid, int32 typmod, int32 ndims)
+ {
+ int i;
+ TypeName *n = makeTypeNameFromOid(typeOid, typmod);
+
+ n->arrayBounds = NIL;
+ for (i = 0; i < ndims; i++)
+ n->arrayBounds = lcons_int(-1, n->arrayBounds);
+
return n;
}
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
new file mode 100644
index c6f3628..3eeb5cd
*** a/src/backend/parser/parse_utilcmd.c
--- b/src/backend/parser/parse_utilcmd.c
*************** transformTableLikeClause(CreateStmtConte
*** 981,988 ****
*/
def = makeNode(ColumnDef);
def->colname = pstrdup(attributeName);
! def->typeName = makeTypeNameFromOid(attribute->atttypid,
! attribute->atttypmod);
def->inhcount = 0;
def->is_local = true;
def->is_not_null = attribute->attnotnull;
--- 981,989 ----
*/
def = makeNode(ColumnDef);
def->colname = pstrdup(attributeName);
! def->typeName = makeTypeNameWithNdimsFromOid(attribute->atttypid,
! attribute->atttypmod,
! attribute->attndims);
def->inhcount = 0;
def->is_local = true;
def->is_not_null = attribute->attnotnull;
diff --git a/src/include/nodes/makefuncs.h b/src/include/nodes/makefuncs.h
new file mode 100644
index 57bd52f..8db4b10
*** a/src/include/nodes/makefuncs.h
--- b/src/include/nodes/makefuncs.h
*************** extern RangeVar *makeRangeVar(char *sche
*** 71,76 ****
--- 71,77 ----
extern TypeName *makeTypeName(char *typnam);
extern TypeName *makeTypeNameFromNameList(List *names);
extern TypeName *makeTypeNameFromOid(Oid typeOid, int32 typmod);
+ extern TypeName *makeTypeNameWithNdimsFromOid(Oid typeOid, int32 typmod, int32 ndims);
extern ColumnDef *makeColumnDef(const char *colname,
Oid typeOid, int32 typmod, Oid collOid);
On 04/16/2018 05:01 PM, Alexey Bashtanov wrote:
As reported in [1], pg_attribute.attndims turns to 0 when 'create
table like/as'.
The patch attached is to fix it.
Hi Alexey,
Judging from the discussion in [1]/messages/by-id/3792.1485959113@sss.pgh.pa.us, attndims is deprecated. Could you
describe what you are trying to achieve with it?
[1]: /messages/by-id/3792.1485959113@sss.pgh.pa.us
--
Alexander Kuzmenkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company