Repository navigation
Closed
Labels
Description
- generated columns
CREATE TABLE people(
color_id int GENERATED ALWAYS AS IDENTITY (START WITH 17 INCREMENT BY 21),
height_cm numeric,
height_in numeric GENERATED ALWAYS AS (height_cm / 2.54) STORED,
gen_def_identity numeric GENERATED BY DEFAULT AS IDENTITY,
gen_alw_identity numeric GENERATED ALWAYS AS IDENTITY
);{
"query": {
"version": 130002,
"stmts": [
{
"stmt": {
"CreateStmt": {
"relation": {
"relname": "people",
"inh": true,
"relpersistence": "p",
"location": 16
},
"tableElts": [
{
"ColumnDef": {
"colname": "color_id",
"typeName": {
"names": [
{
"String": {
"str": "pg_catalog"
}
},
{
"String": {
"str": "int4"
}
}
],
"typemod": -1,
"location": 37
},
"is_local": true,
"constraints": [
{
"Constraint": {
"contype": "CONSTR_IDENTITY",
"location": 41,
"generated_when": "a",
"options": [
{
"DefElem": {
"defname": "start",
"arg": {
"Integer": {
"ival": 17
}
},
"defaction": "DEFELEM_UNSPEC",
"location": 71
}
},
{
"DefElem": {
"defname": "increment",
"arg": {
"Integer": {
"ival": 21
}
},
"defaction": "DEFELEM_UNSPEC",
"location": 85
}
}
]
}
}
],
"location": 28
}
},
{
"ColumnDef": {
"colname": "height_cm",
"typeName": {
"names": [
{
"String": {
"str": "pg_catalog"
}
},
{
"String": {
"str": "numeric"
}
}
],
"typemod": -1,
"location": 117
},
"is_local": true,
"location": 107
}
},
{
"ColumnDef": {
"colname": "height_in",
"typeName": {
"names": [
{
"String": {
"str": "pg_catalog"
}
},
{
"String": {
"str": "numeric"
}
}
],
"typemod": -1,
"location": 140
},
"is_local": true,
"constraints": [
{
"Constraint": {
"contype": "CONSTR_GENERATED",
"location": 148,
"raw_expr": {
"A_Expr": {
"kind": "AEXPR_OP",
"name": [
{
"String": {
"str": "/"
}
}
],
"lexpr": {
"ColumnRef": {
"fields": [
{
"String": {
"str": "height_cm"
}
}
],
"location": 169
}
},
"rexpr": {
"A_Const": {
"val": {
"Float": {
"str": "2.54"
}
},
"location": 181
}
},
"location": 179
}
},
"generated_when": "a"
}
}
],
"location": 130
}
},
{
"ColumnDef": {
"colname": "gen_def_identity",
"typeName": {
"names": [
{
"String": {
"str": "pg_catalog"
}
},
{
"String": {
"str": "numeric"
}
}
],
"typemod": -1,
"location": 216
},
"is_local": true,
"constraints": [
{
"Constraint": {
"contype": "CONSTR_IDENTITY",
"location": 224,
"generated_when": "d"
}
}
],
"location": 199
}
},
{
"ColumnDef": {
"colname": "gen_alw_identity",
"typeName": {
"names": [
{
"String": {
"str": "pg_catalog"
}
},
{
"String": {
"str": "numeric"
}
}
],
"typemod": -1,
"location": 279
},
"is_local": true,
"constraints": [
{
"Constraint": {
"contype": "CONSTR_IDENTITY",
"location": 287,
"generated_when": "a"
}
}
],
"location": 262
}
}
],
"oncommit": "ONCOMMIT_NOOP"
}
},
"stmt_len": 317
}
]
},
"stderr": ""
}
Activity
pyramation commentedon Mar 17, 2021
Seems like it just needs
indexIncludingParams:{ "query": { "version": 130002, "stmts": [ { "stmt": { "IndexStmt": { "idxname": "new_unique_idx", "relation": { "relname": "new_example", "inh": true, "relpersistence": "p", "location": 41 }, "accessMethod": "btree", "indexParams": [ { "IndexElem": { "name": "a", "ordering": "SORTBY_DEFAULT", "nulls_ordering": "SORTBY_NULLS_DEFAULT" } }, { "IndexElem": { "name": "b", "ordering": "SORTBY_DEFAULT", "nulls_ordering": "SORTBY_NULLS_DEFAULT" } } ], "indexIncludingParams": [ { "IndexElem": { "name": "c", "ordering": "SORTBY_DEFAULT", "nulls_ordering": "SORTBY_NULLS_DEFAULT" } } ], "unique": true } }, "stmt_len": 70 } ] }, "stderr": "" }pyramation commentedon Mar 17, 2021
{ "query": { "version": 130002, "stmts": [ { "stmt": { "SelectStmt": { "targetList": [ { "ResTarget": { "name": "timestamp", "val": { "ColumnRef": { "fields": [ { "String": { "str": "t2" } }, { "String": { "str": "timestamp" } } ], "location": 163 } }, "location": 163 } }, { "ResTarget": { "name": "moving_count_num", "val": { "FuncCall": { "funcname": [ { "String": { "str": "avg" } } ], "args": [ { "ColumnRef": { "fields": [ { "String": { "str": "t2" } }, { "String": { "str": "count_num" } } ], "location": 195 } } ], "over": { "orderClause": [ { "SortBy": { "node": { "ColumnRef": { "fields": [ { "String": { "str": "t2" } }, { "String": { "str": "timestamp" } } ], "location": 224 } }, "sortby_dir": "SORTBY_ASC", "sortby_nulls": "SORTBY_NULLS_DEFAULT", "location": -1 } } ], "frameOptions": 3091, "startOffset": { "A_Const": { "val": { "String": { "str": "3 months" } }, "location": 255 } }, "location": 214 }, "location": 191 } }, "location": 191 } } ], "fromClause": [ { "RangeVar": { "relname": "timestamp_measurement", "inh": true, "relpersistence": "p", "alias": { "aliasname": "t2" }, "location": 318 } } ], "limitOption": "LIMIT_OPTION_DEFAULT", "withClause": { "ctes": [ { "CommonTableExpr": { "ctename": "timestamp_measurement", "ctematerialized": "CTEMaterializeDefault", "ctequery": { "SelectStmt": { "targetList": [ { "ResTarget": { "name": "count_num", "val": { "FuncCall": { "funcname": [ { "String": { "str": "count" } } ], "args": [ { "ColumnRef": { "fields": [ { "String": { "str": "t1" } }, { "String": { "str": "id" } } ], "location": 47 } } ], "location": 41 } }, "location": 41 } }, { "ResTarget": { "name": "timestamp", "val": { "FuncCall": { "funcname": [ { "String": { "str": "date_trunc" } } ], "args": [ { "A_Const": { "val": { "String": { "str": "month" } }, "location": 82 } }, { "ColumnRef": { "fields": [ { "String": { "str": "t1" } }, { "String": { "str": "start_date" } } ], "location": 91 } } ], "location": 71 } }, "location": 71 } } ], "fromClause": [ { "RangeVar": { "relname": "trip", "inh": true, "relpersistence": "p", "alias": { "aliasname": "t1" }, "location": 124 } } ], "groupClause": [ { "ColumnRef": { "fields": [ { "String": { "str": "timestamp" } } ], "location": 144 } } ], "limitOption": "LIMIT_OPTION_DEFAULT", "op": "SETOP_NONE" } }, "location": 8 } } ], "location": 3 }, "op": "SETOP_NONE" } } } ] }, "stderr": "" }pyramation commentedon Mar 17, 2021
https://github.com/pyramation/pgsql-parser/tree/feat/13-preview
pyramation commentedon Mar 18, 2021
{ "query": { "version": 130002, "stmts": [ { "stmt": { "AlterTableStmt": { "relation": { "relname": "mytable", "inh": true, "relpersistence": "p", "location": 17 }, "cmds": [ { "AlterTableCmd": { "subtype": "AT_AddColumn", "def": { "ColumnDef": { "colname": "height_in", "typeName": { "names": [ { "String": { "str": "pg_catalog" } }, { "String": { "str": "numeric" } } ], "typemod": -1, "location": 46 }, "is_local": true, "constraints": [ { "Constraint": { "contype": "CONSTR_GENERATED", "location": 54, "raw_expr": { "A_Expr": { "kind": "AEXPR_OP", "name": [ { "String": { "str": "/" } } ], "lexpr": { "ColumnRef": { "fields": [ { "String": { "str": "height_cm" } } ], "location": 75 } }, "rexpr": { "A_Const": { "val": { "Float": { "str": "2.54" } }, "location": 87 } }, "location": 85 } }, "generated_when": "a" } } ], "location": 36 } }, "behavior": "DROP_RESTRICT" } } ], "relkind": "OBJECT_TABLE" } }, "stmt_len": 99 } ] }, "stderr": "" }[-]when we upgrade to PG 12, add these test cases[/-][+]when we upgrade to PG 12/13, add these test cases[/+]