achesui
Explore posts from serversDTDrizzle Team
•Created by achesui on 9/4/2024 in #help
PLEASE HELP WITH SQL OPERATOR DYNAMIC PARAMS
Hello, Im trying to execute a SQL query using SQL operator but it gives error.
NeonDbError: syntax error at or near "$2"
const treshold: number = 0;
const hourProposal = "16:40:00";
const slotInterval = 30;
const appointmentFrom = 1;
const appointmentDay = "2024-09-05";
const initialHour = "10:00";
const finalHour = "17:00";
const availableAppointments: { rows: Appointment[] } = await db.execute(sql
SELECT gs::time AS available_slot
FROM generate_series(
${appointmentDay} ${initialHour}::timestamp,
${appointmentDay} ${finalHour}::timestamp - '${slotInterval} minutes'::interval,
${slotInterval} minutes::interval
) AS gs
LEFT JOIN "create-appointment" ca
ON gs::time = ca."appointment-hour"
AND ca."appointment-day" = ${appointmentDay}
AND ca."appointment-from" = ${appointmentFrom}
WHERE ca."appointment-hour" IS NULL
AND gs::time >= '${currentTime}'::time
AND NOT EXISTS (
SELECT 1
FROM "create-appointment" ca2
WHERE ca2."appointment-day" = '${appointmentDay}'
AND ca2."appointment-from" = ${appointmentFrom}
AND ABS(EXTRACT(EPOCH FROM (gs::time - ca2."appointment-hour"))) < ${slotInterval} * 60
);
);
Thanks!1 replies