On Wed, Dec 11, 2024, at 3:37 AM, Nohez Poonawala wrote:
Currently, the pg_dump tool outputs comments in different formats for
primary/foreign keys and indexes. Below is the comment format.
- for Primary key:
-- Name: TABLENAME CONSTRAINTNAME; Type: CONSTRAINT; Schema: SCHEMA;
Owner: OWNER
- for Foreign key:
-- Name: TABLENAME CONSTRAINTNAME; Type: FK CONSTRAINT; Schema:
SCHEMA; Owner: OWNER
- for Index:
-- Name: INDEXNAME; Type: INDEX; Schema: SCHEMA; Owner: OWNER
To maintain consistency, I suggest modifying the comment format for
indexes to include the associated TABLENAME, similar to constraints.
For example:
- for Index:
-- Name: TABLENAME INDEXNAME; Type: INDEX; Schema: SCHEMA; Owner: OWNER
This small change would improve clarity and make the output format more uniform.
Constraints and indexes are different classes of objects. Per SQL standard,
different tables can have same constraint names. However, different tables
cannot have same index name (SQL standard says nothing about indexes. That's a
Postgres implementation detail.) Having said that, you don't need the table
name to associate it with an index (because it is unique in a schema) but a
constraint requires a table (because there might be multiple constraints with
the same name in a schema). An argument against this inclusion is that it will
increase the output file size without adding a crucial information. You mention
consistency but since it is a different class of objects I don't think this
argument holds much water.