@@ -10,6 +10,7 @@ import {
1010 getCohortCteName ,
1111 getCohortAlias ,
1212 buildCohortMembershipQuery ,
13+ getMaterializedColumns ,
1314} from './chart.service' ;
1415import { onlyReportEvents } from './reports.service' ;
1516import { getCustomEventByName , expandCustomEventToSQL } from './custom-event.service' ;
@@ -46,6 +47,13 @@ export class ConversionService {
4647 } ;
4748 }
4849
50+ // Get materialized columns to ensure UNION compatibility
51+ const materializedColumns = await getMaterializedColumns ( ) ;
52+ const materializedColumnNames = Object . values ( materializedColumns ) ;
53+ const materializedColumnsSelect = materializedColumnNames . length > 0
54+ ? `, ${ materializedColumnNames . join ( ', ' ) } `
55+ : '' ;
56+
4957 // Build CTEs for custom events
5058 const ctes : string [ ] = [ ] ;
5159 const baseWhere = [
@@ -80,8 +88,9 @@ export class ConversionService {
8088 if ( customEvents [ index ] ) {
8189 unionParts . push ( `SELECT * FROM custom_event_${ index } ` ) ;
8290 } else {
91+ // Regular event - include materialized columns to match custom events
8392 unionParts . push ( `
84- SELECT * FROM ${ TABLE_NAMES . events }
93+ SELECT *${ materializedColumnsSelect } FROM ${ TABLE_NAMES . events }
8594 WHERE project_id = '${ projectId } '
8695 AND name = '${ event . name } '
8796 AND created_at BETWEEN toDateTime('${ startDate } ') AND toDateTime('${ endDate } ')
0 commit comments