Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column comments not assiciated to column names #173

Open
erwin-frohsinn opened this issue Nov 21, 2022 · 4 comments
Open

Column comments not assiciated to column names #173

erwin-frohsinn opened this issue Nov 21, 2022 · 4 comments

Comments

@erwin-frohsinn
Copy link

Describe the bug
A DDL containing COMMENT ON COLUMN does not associate the comment to the column

To Reproduce
run this:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from simple_ddl_parser import DDLParser
from pprint import pprint

parse_results = DDLParser("""-- something.t_spiel definition

-- Drop table

-- DROP TABLE something.t_spiel;

CREATE TABLE something.t_spiel (
	id varchar(5) NOT NULL,
	refprodid varchar(10) NULL,
	titel varchar(100) NOT NULL,
	refsaalid varchar(10) NULL, -- Verweis auf den Saal
	freieplatzwahl bool NOT NULL DEFAULT true, -- Ja/Nein
	CONSTRAINT idx_t_spiel_primary PRIMARY KEY (id)
);

-- Column comments

-- COMMENT ON COLUMN something.t_spiel.refsaalid IS 'Verweis auf den Saal';
-- COMMENT ON COLUMN something.t_spiel.freieplatzwahl IS 'Ja/Nein';

-- something.t_spiel foreign keys

ALTER TABLE something.t_spiel ADD CONSTRAINT "foreign_key_Ref_Prod_Id" FOREIGN KEY (refprodid) REFERENCES something.t_produktion(id);
ALTER TABLE something.t_spiel ADD CONSTRAINT "foreign_key_Ref_Saal_Id" FOREIGN KEY (refsaalid) REFERENCES something.t_saal(id);
""",silent=True).run(output_mode='sql')

pprint(parse_results)

This code produces
... {'comments': [' Verweis auf den Saal', ' Ja/Nein']}...

which is just a collection of comments w/o reference to the fields they belong to.

Expected behavior
something like
{'comments': {'something.t_spiel.refsaalid': ' Verweis auf den Saal', 'something.t_spiel.freieplatzwahl': ' Ja/Nein'}}...
should be generated, or even better for postprocessing, the comment should be added to the field description:
{'check': None,
'default': None,
'name': 'refsaalid',
...
'comment': 'Verweis auf den Saal' },

Desktop (please complete the following information):

  • Database: Postgresql
  • DDL created with DBeaver
@xnuinside
Copy link
Owner

@erwin-frohsinn hi! Thanks for opening the issue, can you provide the link to the doc for such type of comments? Normally in sql doble ‘-‘ mean start of the comments that are ignored in SQL interpretation and it is just a comment in the document without any associations

@erwin-frohsinn
Copy link
Author

erwin-frohsinn commented Nov 21, 2022 via email

@ahaessly
Copy link

ahaessly commented Feb 22, 2023

Hi. I have also run into the same problem.
Just to clarify, these are not comments within the ddl that start with "--". These are SQL statements that add comments to tables, columns, etc.
Also, I'm not seeing any 'comments' entry in my json.

I would also like to see the comments added to the appropriate item. For example, if the ddl has a COMMENT ON TABLE, the comment should be added under the table json node. And when there is a COMMENT ON COLUMN, the comment should be added under the column json node.

For example, this ddl:

--
-- PostgreSQL database dump
--


CREATE TABLE public."Diagnosis" (
    id text NOT NULL,
);


COMMENT ON TABLE public."Diagnosis" IS 'A collection of characteristics that describe an abnormal condition of the body as assessed at a point in time. May be used to capture information about neoplastic and non-neoplastic conditions.';

produced this json (no comment section):

[
 {
  "columns": [
   {
    "name": "id",
    "type": "text",
    "size": null,
    "references": null,
    "unique": false,
    "nullable": false,
    "default": null,
    "check": null
   }
  ],
  "primary_key": [],
  "alter": {},
  "checks": [],
  "index": [],
  "partitioned_by": [],
  "tablespace": null,
  "schema": "public",
  "table_name": "\"Diagnosis\""
 }
]

@tduval-unifylogic
Copy link

greetings! any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants