Seaquel
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.

SQLSTATE42P13
Condition nameinvalid_function_definition
Class42 — 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);

Source: PostgreSQL documentation, Appendix A