Skip to content

when we upgrade to PG 12/13, add these test cases #16

Closed

Description

@pyramation
  • 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

  1. pyramation commented on Mar 17, 2021

    @pyramation
    CollaboratorAuthor
    • include index

    Seems like it just needs indexIncludingParams:

    CREATE UNIQUE INDEX new_unique_idx ON new_example(a, b)
    INCLUDE (c);
    {
      "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": ""
    }
  2. pyramation commented on Mar 17, 2021

    @pyramation
    CollaboratorAuthor
    • preceding
    WITH timestamp_measurement AS (SELECT count(t1.id) AS count_num
                                        , date_trunc('month', t1.start_date) AS timestamp
                                   FROM trip AS t1
                                   GROUP BY timestamp)
    
      SELECT t2.timestamp AS timestamp
           , avg(t2.count_num) OVER (ORDER BY t2.timestamp ASC RANGE BETWEEN '3 months' PRECEDING AND CURRENT ROW) AS moving_count_num
      FROM timestamp_measurement AS t2
    {
    "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": ""
    }
  3. pyramation commented on Mar 17, 2021

    @pyramation
    CollaboratorAuthor
  4. pyramation commented on Mar 18, 2021

    @pyramation
    CollaboratorAuthor
    ALTER TABLE mytable ADD COLUMN height_in numeric GENERATED ALWAYS AS (height_cm / 2.54) STORED;
    {
      "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": ""
    }
  5. changed the title [-]when we upgrade to PG 12, add these test cases[/-] [+]when we upgrade to PG 12/13, add these test cases[/+] on Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions