如何获得视图定义?

时间:2019-07-11 20:21:37

标签: schemacrawler

我想从PostgreSQL模式中获取视图定义,以便可以在目标数据库上创建相同的视图。我从SchemaCrawler获取了所有信息,但View所基于的表除外。这可能吗?还是可以使用SchemaCrawler包括基表名称来代替View定义?

我尝试设置-parents开关,以查看View是否包含“ parent”表,但没有得到此类信息。

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

     {
      "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脚本。

谢谢!

0 个答案:

没有答案