summaryrefslogtreecommitdiff
path: root/sql/modules/Entity.sql
blob: ba98c62a884318f095f5ea074abb729cb58331cf (plain)
  1. --
  2. BEGIN;
  3. CREATE OR REPLACE FUNCTION entity_save(
  4. in_entity_id int, in_name text, in_entity_class INT
  5. ) RETURNS INT AS $$
  6. DECLARE
  7. e entity;
  8. e_id int;
  9. BEGIN
  10. select * into e from entity where id = in_entity_id;
  11. update
  12. entity
  13. SET
  14. name = in_name,
  15. entity_class = in_entity_class
  16. WHERE
  17. id = in_entity_id;
  18. IF NOT FOUND THEN
  19. -- do the insert magic.
  20. e_id = nextval('entity_id_seq');
  21. insert into entity (id, name, entity_class) values
  22. (e_id,
  23. in_name,
  24. in_entity_class
  25. );
  26. return e_id;
  27. END IF;
  28. return in_entity_id;
  29. END;
  30. $$ language 'plpgsql';
  31. commit;