0

我想从 PostgreSQL 模式中获取视图定义,以便我可以在目标数据库上创建相同的视图。除了视图所基于的表之外,我从 SchemaCrawler 获得了所有信息。这可能吗?或者 SchemaCrawler 是否可以包含基表名称而不是 View 定义?

我尝试设置 -parents 开关以查看视图是否包含“父”表,但我没有得到这样的信息。

[编辑]
这就是我得到的:

     {
      "foreignKeys": [],
      "indexes": [],
      "columns": [
        {
          "size": 50,
          "nullable": true,
          "databaseSpecificType": "varchar",
          "generated": false,
          "dataType": "VARCHAR",
          "name": "view_description",
          "width": "",
          "decimalDigits": 0,
          "remarks": "",
          "autoIncremented": false
        },
        {
          "size": 10,
          "nullable": true,
          "databaseSpecificType": "numeric",
          "generated": false,
          "dataType": "NUMERIC",
          "name": "revenue",
          "width": "(10, 0)",
          "decimalDigits": 0,
          "remarks": "",
          "autoIncremented": false
        },
        {
          "size": 10,
          "nullable": true,
          "databaseSpecificType": "numeric",
          "generated": false,
          "dataType": "NUMERIC",
          "name": "assets",
          "width": "(10, 0)",
          "decimalDigits": 0,
          "remarks": "",
          "autoIncremented": false
        },
      ],
      "name": "my_view",
      "definition": "",
      "type": "view",
      "triggers": [],
      "tableConstraints": [],
      "remarks": "",
      "primaryKey": {}
    }

这就是我所期待的:

{
  "foreignKeys": [],
  "indexes": [],
  "columns": [
    {
      "size": 50,
      "nullable": true,
      "databaseSpecificType": "varchar",
      "generated": false,
      "dataType": "VARCHAR",
      "name": "view_description",
      "width": "",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    },
    {
      "size": 10,
      "nullable": true,
      "databaseSpecificType": "numeric",
      "generated": false,
      "dataType": "NUMERIC",
      "name": "revenue",
      "width": "(10, 0)",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    },
    {
      "size": 10,
      "nullable": true,
      "databaseSpecificType": "numeric",
      "generated": false,
      "dataType": "NUMERIC",
      "name": "assets",
      "width": "(10, 0)",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    },
  ],
  "name": "my_view",
  "definition": "CREATE VIEW my_view ...",
  "type": "view",
  "triggers": [],
  "tableConstraints": [],
  "remarks": "",
  "primaryKey": {}
}

或者有一个类似 "parentTable": "my_table" 的条目,我可以使用它通过模板或代码构建 CREATE VIEW 脚本。

谢谢!

4

0 回答 0