@@ -14,9 +14,19 @@ import { TypeId, TypeFormat } from 'pg-types';
1414import * as moment from 'moment' ;
1515import {
1616 BaseDriver ,
17- DownloadQueryResultsOptions , DownloadTableMemoryData , DriverInterface ,
18- GenericDataBaseType , IndexesSQL , TableStructure , StreamOptions ,
19- StreamTableDataWithTypes , QueryOptions , DownloadQueryResultsResult , DriverCapabilities , TableColumn ,
17+ DownloadQueryResultsOptions ,
18+ DownloadTableMemoryData ,
19+ DriverInterface ,
20+ GenericDataBaseType ,
21+ IndexesSQL ,
22+ TableStructure ,
23+ StreamOptions ,
24+ StreamTableDataWithTypes ,
25+ QueryOptions ,
26+ DownloadQueryResultsResult ,
27+ DriverCapabilities ,
28+ TableColumn ,
29+ TableColumnQueryResult ,
2030} from '@cubejs-backend/base-driver' ;
2131import { QueryStream } from './QueryStream' ;
2232
@@ -291,6 +301,23 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
291301 } ) ;
292302 }
293303
304+ public override async tableColumnTypes ( table : string ) : Promise < TableStructure > {
305+ const [ schema , name ] = table . split ( '.' ) ;
306+
307+ const columns = await this . query < TableColumnQueryResult > (
308+ `SELECT columns.column_name as ${ this . quoteIdentifier ( 'column_name' ) } ,
309+ columns.table_name as ${ this . quoteIdentifier ( 'table_name' ) } ,
310+ columns.table_schema as ${ this . quoteIdentifier ( 'table_schema' ) } ,
311+ columns.data_type as ${ this . quoteIdentifier ( 'data_type' ) }
312+ FROM information_schema.columns
313+ WHERE table_name = '${ this . param ( 0 ) } ' AND table_schema = '${ this . param ( 1 ) } '
314+ ${ getEnv ( 'fetchColumnsByOrdinalPosition' ) ? 'ORDER BY columns.ordinal_position' : '' } ` ,
315+ [ name , schema ]
316+ ) ;
317+
318+ return columns . map ( c => ( { name : c . column_name , type : this . toGenericType ( c . data_type ) } ) ) ;
319+ }
320+
294321 public async stream (
295322 query : string ,
296323 values : unknown [ ] ,
0 commit comments