Sitelet https://github.com/dbgate/dbgate/issues/1494
Skip to content

BUG: "show sql" and "view structure" does not show a table's layout correctly when using a functional index #1494

Description

@KanchiMoe

Describe the bug

When viewing a table's structure or generating its SQL, functional indexes (e.g., CREATE UNIQUE INDEX ... ON table (column, md5(xml_column::text))) are not shown in the output. The table appears to have fewer indexes than it actually does.

To Reproduce
Steps to reproduce the behavior:
This was done using postgres databases.

  1. Create a table, using a query/SQL
CREATE TABLE IF NOT EXISTS "public"."test12345" (
    "run_uuid" UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
    "run_time" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    "extracted_feed_uuid" UUID NOT NULL,
    "extracted_timestamp" TIMESTAMP WITH TIME ZONE NOT NULL,
    "feed_xml" XML NOT NULL
);
  1. Run this query.
  2. On completion, you may need to reload, or exit out and reopen, DBgate for the table to appear in the bottom left of the screen.
  3. In the same database when you ran the first query, run this query
CREATE UNIQUE INDEX IF NOT EXISTS "test54321"
ON "public"."test12345" (
    "extracted_feed_uuid",
    "extracted_timestamp",
    md5("feed_xml"::text)
);

Make note of that md5 part.

When successful, close and reopen DBgate again.

Right click on the table in the bottom left, then "show SQL".

You will see this:

CREATE TABLE "public"."test12345" ( 
  "run_uuid" UUID NOT NULL DEFAULT gen_random_uuid() ,
  "run_time" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now() ,
  "extracted_feed_uuid" UUID NOT NULL,
  "extracted_timestamp" TIMESTAMP WITH TIME ZONE NOT NULL,
  "feed_xml" XML NOT NULL,
  CONSTRAINT "test12345_pkey" PRIMARY KEY ("run_uuid")
);
CREATE UNIQUE INDEX "test54321" 
ON "public"."test12345" (
  "extracted_feed_uuid" ASC,
  "extracted_timestamp" ASC
);

It's missing the md5 section.

Further, when using "structure" view, it doesn't appear correctly either

Image Image

Expected behavior
This is the view when using the terminal/psql:

                                 Table "public.test12345"
       Column        |           Type           | Collation | Nullable |      Default      
---------------------+--------------------------+-----------+----------+-------------------
 run_uuid            | uuid                     |           | not null | gen_random_uuid()
 run_time            | timestamp with time zone |           | not null | now()
 extracted_feed_uuid | uuid                     |           | not null | 
 extracted_timestamp | timestamp with time zone |           | not null | 
 feed_xml            | xml                      |           | not null | 
Indexes:
    "test12345_pkey" PRIMARY KEY, btree (run_uuid)
    "test54321" UNIQUE, btree (extracted_feed_uuid, extracted_timestamp, md5(feed_xml::text))

This is how DBeaver shows it

Image Image

Version Information (please complete the following information):

  • OS: Linux
  • App Version: 7.2.1, build date 2026-06-19
  • Install source: DBgate website download
  • Type - Application
  • Database engine: PostgreSQL 18.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions