PostgreSQL error code
PostgreSQL error 42P13
42P13 is the SQLSTATE PostgreSQL reports for invalid function definition, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42P13 |
|---|---|
| Condition name | invalid_function_definition |
| Class | 42 — Syntax Error or Access Rule Violation |
Reproduce it, then fix it
The function is declared to return integer, but its last SELECT returns text. Change the declared type, or the query, so they agree. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
CREATE FUNCTION product_label(p_id int) RETURNS int AS $$ SELECT name FROM products WHERE id = p_id $$ LANGUAGE sql;
CREATE FUNCTION product_label(p_id int) RETURNS text AS $$ SELECT name FROM products WHERE id = p_id $$ LANGUAGE sql; SELECT product_label(1);