fix: quote "event" reserved keyword in journey queries

Fixes PostgreSQL syntax error by quoting the "event" column alias. This was causing the journey query to fail.

"event" is a reserved keyword in PostgreSQL. Added double quotes to treat it as an identifier rather than a keyword.

Changes:
- Quote "event" in PostgreSQL
- Quote "event" in ClickHouse for consistency
This commit is contained in:
rkoh-rq 2025-11-04 11:00:33 +08:00 committed by GitHub
parent 777515f754
commit 3cb7fa34b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,7 +72,7 @@ async function relationalQuery(
for (let i = 1; i <= steps; i++) {
const endQuery = i < steps ? ',' : '';
selectQuery += `s.e${i},`;
maxQuery += `\nmax(CASE WHEN event_number = ${i} THEN event ELSE NULL END) AS e${i}${endQuery}`;
maxQuery += `\nmax(CASE WHEN event_number = ${i} THEN "event" ELSE NULL END) AS e${i}${endQuery}`;
groupByQuery += `s.e${i}${endQuery} `;
}
@ -118,7 +118,7 @@ async function relationalQuery(
select distinct
visit_id,
referrer_path,
coalesce(nullIf(event_name, ''), url_path) event,
coalesce(nullIf(event_name, ''), url_path) "event",
row_number() OVER (PARTITION BY visit_id ORDER BY created_at) AS event_number
from website_event
where website_id = {{websiteId::uuid}}
@ -182,7 +182,7 @@ async function clickhouseQuery(
for (let i = 1; i <= steps; i++) {
const endQuery = i < steps ? ',' : '';
selectQuery += `s.e${i},`;
maxQuery += `\nmax(CASE WHEN event_number = ${i} THEN event ELSE NULL END) AS e${i}${endQuery}`;
maxQuery += `\nmax(CASE WHEN event_number = ${i} THEN "event" ELSE NULL END) AS e${i}${endQuery}`;
groupByQuery += `s.e${i}${endQuery} `;
}
@ -227,7 +227,7 @@ async function clickhouseQuery(
WITH events AS (
select distinct
visit_id,
coalesce(nullIf(event_name, ''), url_path) event,
coalesce(nullIf(event_name, ''), url_path) "event",
row_number() OVER (PARTITION BY visit_id ORDER BY created_at) AS event_number
from website_event
where website_id = {websiteId:UUID}