-
Notifications
You must be signed in to change notification settings - Fork 212
Open
Description
Query
The query is incorrect, because there is no = between WHERE customer_id $1 however pg_query_free_plpgsql_parse_result(query) returns correctly.
#include <pg_query.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
PgQueryPlpgsqlParseResult result;
result = pg_query_parse_plpgsql(" \
CREATE OR REPLACE FUNCTION update_customer_total_sales(customer_id INT) \
RETURNS VOID AS $$ \
DECLARE \
total NUMERIC; \
BEGIN \
SELECT COALESCE(SUM(amount), 0) INTO total \
FROM orders \
WHERE customer_id $1; \
UPDATE customers \
SET total_sales = total \
WHERE customer_id; \
RAISE NOTICE 'Total sales for customer ID %: %', customer_id, total; \
END; \
$$ LANGUAGE plpgsql;");
if (result.error) {
printf("error: %s at %d\n", result.error->message, result.error->cursorpos);
} else {
printf("%s\n", result.plpgsql_funcs);
}
pg_query_free_plpgsql_parse_result(result);
// Optional, this ensures all memory is freed upon program exit (useful when running Valgrind)
pg_query_exit();
return 0;
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels