You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WHEN a.atttypid IN (1042, 1043) /* char, varchar */
635
+
THEN a.atttypmod - 4
636
+
WHEN a.atttypid IN (1560, 1562) /* bit, varbit */
637
+
THEN a.atttypmod
638
+
ELSE
639
+
NULL
640
+
END AS character_maximum_length,
641
+
CASE a.atttypid
642
+
WHEN 21 /*int2*/ THEN 16
643
+
WHEN 23 /*int4*/ THEN 32
644
+
WHEN 20 /*int8*/ THEN 64
645
+
WHEN 1700 /*numeric*/ THEN
646
+
CASE
647
+
WHEN a.atttypmod = -1
648
+
THEN NULL
649
+
ELSE ((a.atttypmod - 4) >> 16) & 65535
650
+
END
651
+
WHEN 700 /*float4*/ THEN 24 /*FLT_MANT_DIG*/
652
+
WHEN 701 /*float8*/ THEN 53 /*DBL_MANT_DIG*/
653
+
ELSE NULL
654
+
END AS numeric_precision,
655
+
CASE
656
+
WHEN a.atttypid IN (21, 23, 20) /* int */ THEN 0
657
+
WHEN a.atttypid IN (1700) /* numeric */ THEN
658
+
CASE
659
+
WHEN a.atttypmod = -1
660
+
THEN NULL
661
+
ELSE (a.atttypmod - 4) & 65535
662
+
END
663
+
ELSE NULL
664
+
END AS numeric_scale
665
+
FROM pg_catalog.pg_class c
666
+
JOIN pg_catalog.pg_namespace ns ON ns.oid = c.relnamespace
667
+
JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
668
+
WHERE
669
+
/* tables, views, materialized views */
670
+
c.relkind in ('r', 'v', 'm')
671
+
AND ns.nspname = '{schema}'
672
+
AND c.relname = '{table}'
673
+
AND a.attname = '{column}'
674
+
ORDER BY nspname, relname, attnum
675
+
""".format(
676
+
schema=datasource["schema"],
677
+
table=datasource["table_name"],
678
+
column=column
679
+
))
680
+
results=conn.execute(sql_mv)
681
+
682
+
683
+
row=results.mappings().fetchone()
684
+
ifnotrow:
685
+
self.logger.warn(f"Failed to query column metadata of column {column} from table {datasource["schema"]}.{datasource["table_name"]} of {datasource["database"]}")
686
+
return
687
+
688
+
# Field data type
689
+
data_type=row['data_type']
690
+
field_metadata['data_type'] =data_type
691
+
692
+
ifnotdata_type_only:
693
+
# Constraints from data type
694
+
# NOTE: any existing QGIS field constraints take precedence
self.logger.warn(f"Failed to query column metadata of column {column} from table {datasource["schema"]}.{datasource["table_name"]} of {datasource["database"]}")
0 commit comments