Skip to content

Commit 3ac3ce1

Browse files
committed
Update postgresql
1 parent f885bd5 commit 3ac3ce1

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/postgresql_data_dictionary_creator.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
import os
88

99
from text_2_sql_core.utils.database import DatabaseEngine
10-
from text_2_sql_core.connectors.postgresql_sql import PostgresSqlConnector
10+
from text_2_sql_core.connectors.postgresql_sql import PostgresqlSqlConnector
1111

1212

1313
class PostgresqlDataDictionaryCreator(DataDictionaryCreator):
1414
def __init__(self, **kwargs):
1515
"""A method to initialize the DataDictionaryCreator class."""
16-
super().__init__(**kwargs)
16+
excluded_schemas = ["information_schema", "pg_catalog"]
17+
super().__init__(excluded_schemas=excluded_schemas, **kwargs)
1718

1819
self.database = os.environ["Text2Sql__DatabaseName"]
1920
self.database_engine = DatabaseEngine.POSTGRESQL
2021

21-
self.sql_connector = PostgresSqlConnector()
22+
self.sql_connector = PostgresqlSqlConnector()
2223

2324
@property
2425
def extract_table_entities_sql_query(self) -> str:
@@ -29,33 +30,36 @@ def extract_table_entities_sql_query(self) -> str:
2930
pg_catalog.obj_description(c.oid, 'pg_class') AS "Definition"
3031
FROM
3132
information_schema.tables t
32-
JOIN
33-
pg_catalog.pg_class c ON c.relname = t.table_name
34-
AND c.relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = t.table_schema)
3533
LEFT JOIN
36-
pg_catalog.pg_description pd ON pd.objoid = c.oid
34+
pg_catalog.pg_class c
35+
ON c.relname = t.table_name
36+
AND c.relnamespace = (
37+
SELECT oid
38+
FROM pg_catalog.pg_namespace
39+
WHERE nspname = t.table_schema
40+
)
3741
WHERE
3842
t.table_type = 'BASE TABLE'
39-
AND pd.objsubid = 0 -- 0 indicates the table description, not column descriptions
4043
ORDER BY
4144
"EntitySchema", "Entity";"""
4245

4346
@property
4447
def extract_view_entities_sql_query(self) -> str:
4548
"""A property to extract view entities from a PostgreSQL database."""
4649
return """SELECT
47-
v.viewname AS "Entity",
48-
v.schemaname AS "EntitySchema",
50+
v.table_name AS "Entity",
51+
v.table_schema AS "EntitySchema",
4952
pg_catalog.obj_description(c.oid, 'pg_class') AS "Definition"
5053
FROM
51-
pg_catalog.pg_views v
52-
JOIN
53-
pg_catalog.pg_class c ON c.relname = v.viewname
54-
AND c.relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = v.schemaname)
54+
information_schema.views v
5555
LEFT JOIN
56-
pg_catalog.pg_description pd ON pd.objoid = c.oid
57-
WHERE
58-
pd.objsubid = 0 -- 0 indicates the view description, not a column description
56+
pg_catalog.pg_class c
57+
ON c.relname = v.table_name
58+
AND c.relnamespace = (
59+
SELECT oid
60+
FROM pg_catalog.pg_namespace
61+
WHERE nspname = v.table_schema
62+
)
5963
ORDER BY
6064
"EntitySchema", "Entity";"""
6165

@@ -95,7 +99,7 @@ def extract_entity_relationships_sql_query(self) -> str:
9599
FROM
96100
pg_constraint fk
97101
INNER JOIN
98-
pg_attribute fk_col ON fk.conrelid = fk_col.attrelid AND fk.attnum = fk_col.attnum
102+
pg_attribute fk_col ON fk.conrelid = fk_col.attrelid AND fk.conkey[1] = fk_col.attnum
99103
INNER JOIN
100104
pg_class fk_tab ON fk.conrelid = fk_tab.oid
101105
INNER JOIN

0 commit comments

Comments
 (0)