Skip to content

[BUG] view ddl fail to show for PostgreSQL #1551

Closed
@elsha-phytech

Description

@elsha-phytech
  • Database type and version:
SELECT version();
version
PostgreSQL 14.10 on aarch64-unknown-linux-gnu, compiled by aarch64-unknown-linux-gnu-gcc (GCC) 9.5.0, 64-bit

When trying to get a view structure (ddl) in PG DB I get a blank result:

Image


I went on and did a little skim through the code. This is the lines I've found:

showViewSource(database: string, table: string): string {
return `SELECT CONCAT('CREATE VIEW ',table_name,'\nAS\n(',regexp_replace(view_definition,';$',''),')') "Create View",table_name,view_definition from information_schema.views where table_schema='${database}' and table_name='${table}';`
}

I think this syntax is the problem, and should be changed to:

showViewSource(database: string, table: string): string {
        return `select pg_get_viewdef('${database}.${name}' :: regclass) "Create View",'${name}' "View";`;    }

This type of query seems to work in my case.
You can also use the pg_views view if it prefferd (https://dba.stackexchange.com/a/301076).


Best regards.
Elsha

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions