LoverAndrew commented on issue #6054:
URL: https://github.com/apache/seatunnel/issues/6054#issuecomment-1884081368

   PostgresCatalog's SELECT_COLUMNS_SQL_TEMPLATE has the some issue.
   Before sql statement is
   
![image](https://github.com/apache/seatunnel/assets/3733687/2748556c-4892-4f56-83a5-eaecb1c41298)
   
   ```
   SELECT 
       a.attname AS column_name, 
   t.typname as type_name,
       CASE 
           WHEN t.typname = 'varchar' THEN t.typname || '(' || (a.atttypmod - 
4) || ')'
           WHEN t.typname = 'bpchar' THEN 'char' || '(' || (a.atttypmod - 4) || 
')'
           WHEN t.typname = 'numeric' OR t.typname = 'decimal' THEN t.typname 
|| '(' || ((a.atttypmod - 4) >> 16) || ', ' || ((a.atttypmod - 4) & 65535) || 
')'
           WHEN t.typname = 'bit' OR t.typname = 'bit varying' THEN t.typname 
|| '(' || (a.atttypmod - 4) || ')'
           ELSE t.typname
       END AS full_type_name,
       CASE
           WHEN t.typname IN ('varchar', 'bpchar', 'bit', 'bit varying') THEN 
a.atttypmod - 4
           WHEN t.typname IN ('numeric', 'decimal') THEN (a.atttypmod - 4) >> 16
           ELSE NULL
       END AS column_length,
   CASE
           WHEN t.typname IN ('numeric', 'decimal') THEN (a.atttypmod - 4) & 
65535
           ELSE NULL
       END AS column_scale,
   d.description AS column_comment,
   pg_get_expr(ad.adbin, ad.adrelid) AS default_value,
   CASE WHEN a.attnotnull THEN 'NO' ELSE 'YES' END AS is_nullable
   FROM 
       pg_class c
       JOIN pg_namespace n ON c.relnamespace = n.oid
       JOIN pg_attribute a ON a.attrelid = c.oid
       JOIN pg_type t ON a.atttypid = t.oid
       LEFT JOIN pg_description d ON c.oid = d.objoid AND a.attnum = d.objsubid
       LEFT JOIN pg_attrdef ad ON a.attnum = ad.adnum AND a.attrelid = 
ad.adrelid
   WHERE 
       n.nspname = 'public'
       AND c.relname = 'test_type_table'
       AND a.attnum > 0
   ORDER BY 
       a.attnum;
   ```
   
   After sql statement is
   
![image](https://github.com/apache/seatunnel/assets/3733687/e88385a4-7eb7-4170-b4c3-dec406c51036)
   
   SELECT 
       a.attname AS column_name, 
   isc.udt_name as type_name,
       CASE 
           WHEN isc.udt_name = 'varchar' THEN isc.udt_name || '(' || 
(isc.character_maximum_length) || ')'
           WHEN isc.udt_name = 'bpchar' THEN 'char' || '(' || 
(isc.character_maximum_length) || ')'
           WHEN isc.udt_name = 'numeric' OR isc.udt_name = 'decimal' THEN 
isc.udt_name || '(' || (isc.numeric_precision) || ', ' || (isc.numeric_scale) 
|| ')'
           WHEN isc.udt_name = 'bit' OR isc.udt_name = 'bit varying' THEN 
isc.udt_name || '(' || (isc.character_maximum_length ) || ')'
           ELSE isc.udt_name
       END AS full_type_name,
       CASE
           WHEN isc.udt_name IN ('varchar', 'bpchar', 'bit', 'bit 
varying','text','json','') THEN isc.character_maximum_length
                                WHEN isc.udt_name IN 
('time','timetz','timestampt','timestamptz','date') THEN isc.datetime_precision
           ELSE isc.numeric_precision
       END AS column_length,
   isc.numeric_scale AS column_scale,
   d.description AS column_comment,
   pg_get_expr(ad.adbin, ad.adrelid) AS default_value,
   CASE WHEN a.attnotnull THEN 'NO' ELSE 'YES' END AS is_nullable
   FROM 
                information_schema.columns isc 
                LEFT JOIN pg_namespace n ON n.nspname = isc.table_schema
                LEFT JOIN pg_class c ON isc.table_name = c.relname AND n.oid= 
c.relnamespace
                LEFT JOIN pg_attribute a ON a.attrelid = c.oid AND a.attname = 
isc.column_name
       LEFT JOIN pg_description d ON c.oid = d.objoid AND a.attnum = d.objsubid
       LEFT JOIN pg_attrdef ad ON a.attnum = ad.adnum AND a.attrelid = 
ad.adrelid
   WHERE 
       isc.table_schema = 'public'
       AND c.relname = 'test_type_table'
       AND a.attnum > 0
   ORDER BY 
       a.attnum;


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to