villebro commented on a change in pull request #13294:
URL: https://github.com/apache/superset/pull/13294#discussion_r583015764
##########
File path: superset/db_engine_specs/postgres.py
##########
@@ -45,6 +48,28 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
engine = ""
engine_name = "PostgreSQL"
+ column_type_mappings = (
+ (re.compile(r"^smallint", re.IGNORECASE), types.SMALLINT),
+ (re.compile(r"^integer", re.IGNORECASE), types.INTEGER),
+ (re.compile(r"^bigint", re.IGNORECASE), types.BIGINT),
+ (re.compile(r"^decimal", re.IGNORECASE), types.DECIMAL),
+ (re.compile(r"^numeric", re.IGNORECASE), types.NUMERIC),
+ (re.compile(r"^real", re.IGNORECASE), types.REAL),
+ (re.compile(r"^double precision", re.IGNORECASE), DOUBLE_PRECISION),
+ (re.compile(r"^smallserial", re.IGNORECASE), types.SMALLINT),
+ (re.compile(r"^serial", re.IGNORECASE), types.INTEGER),
+ (re.compile(r"^bigserial", re.IGNORECASE), types.BIGINT),
+ (re.compile(r"^varchar", re.IGNORECASE), types.VARCHAR),
+ (re.compile(r"^char", re.IGNORECASE), types.CHAR),
+ (re.compile(r"^text", re.IGNORECASE), types.TEXT),
+ (re.compile(r"^date", re.IGNORECASE), types.DATE),
+ (re.compile(r"^time", re.IGNORECASE), types.TIME),
+ (re.compile(r"^timestamp", re.IGNORECASE), types.TIMESTAMP),
+ (re.compile(r"^timestamptz", re.IGNORECASE),
types.TIMESTAMP(timezone=True)),
Review comment:
Were you able to get these from `inspector.get_columns()` or
`cursor.description`? When I check a table with timestamps it seems to return
the unabbreviated format `TIMESTAMP WITHOUT TIME ZONE`, not `TIMESTAMP`:

I'm assuming the abbreviations are usually relevant when creating tables,
not fetching table metadata, but I may be wrong (this may have changed over the
versions/years):

##########
File path: superset/db_engine_specs/postgres.py
##########
@@ -45,6 +48,28 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
engine = ""
engine_name = "PostgreSQL"
+ column_type_mappings = (
+ (re.compile(r"^smallint", re.IGNORECASE), types.SMALLINT),
+ (re.compile(r"^integer", re.IGNORECASE), types.INTEGER),
+ (re.compile(r"^bigint", re.IGNORECASE), types.BIGINT),
+ (re.compile(r"^decimal", re.IGNORECASE), types.DECIMAL),
+ (re.compile(r"^numeric", re.IGNORECASE), types.NUMERIC),
+ (re.compile(r"^real", re.IGNORECASE), types.REAL),
+ (re.compile(r"^double precision", re.IGNORECASE), DOUBLE_PRECISION),
+ (re.compile(r"^smallserial", re.IGNORECASE), types.SMALLINT),
+ (re.compile(r"^serial", re.IGNORECASE), types.INTEGER),
+ (re.compile(r"^bigserial", re.IGNORECASE), types.BIGINT),
+ (re.compile(r"^varchar", re.IGNORECASE), types.VARCHAR),
+ (re.compile(r"^char", re.IGNORECASE), types.CHAR),
+ (re.compile(r"^text", re.IGNORECASE), types.TEXT),
+ (re.compile(r"^date", re.IGNORECASE), types.DATE),
+ (re.compile(r"^time", re.IGNORECASE), types.TIME),
+ (re.compile(r"^timestamp", re.IGNORECASE), types.TIMESTAMP),
+ (re.compile(r"^timestamptz", re.IGNORECASE),
types.TIMESTAMP(timezone=True)),
+ (re.compile(r"^interval", re.IGNORECASE), types.Interval),
+ (re.compile(r"^boolean", re.IGNORECASE), types.BOOLEAN),
+ )
Review comment:
We should add at least `DbColumnType` in this mapping, too (should be
added to `ColumnSpec`), as we want to pass that when returning chart query data
to the frontend. This will make `is_dttm` redundant, as that info is already
covered by `DbColumnType.TEMPORAL`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]