1
CREATE FUNCTION insert_m_a_k("odOrganizacijaId" uuid, "doOrganizacijaId" uuid) RETURNS boolean AS
$BODY$BEGIN 
    INSERT INTO mapper_a_k (id, model_a_k_id, organizacija_id, k_a_k, k_a_k_ime, aktiven, deleted)
    SELECT  uuid_generate_v4(), model_a_k_id, doOrganizacijaId , k_a_k, k_a_k_ime, aktiven, deleted 
    FROM mapper_a_k WHERE organizacija_id = odOrganizacijaId AND deleted = false;
END;$BODY$
LANGUAGE sql VOLATILE NOT LEAKPROOF;
  • 1
    Remove BEGIN-END wrapper. – Akina Sep 27 at 8:16
  • 1
    "odOrganizacijaId", odOrganizacijaId: these are different. Read on how Postgres quotes table/column names and variables. You either use quoted names everywhere or not at all. – ypercubeᵀᴹ Sep 27 at 8:16
1

PostgreSQL has several languages for functions, and it is easy to get confused.

PL/pgSQL uses BEGIN / END blocks.

But LANGUAGE sql functions consist only of SQL statements with no blocks ir other procedural elements.

So either change the language to plpgsql and add a semicolon or (better) remove the BEGIN / END block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.