S
S
slonik66634442017-02-02 21:33:23
PostgreSQL
slonik6663444, 2017-02-02 21:33:23

How to build a function in postgresql?

How to build a function in postgresql that will take an argument and, under certain conditions, will, for example, update some data in a table?

CREATE FUNCTION fun2 (integer) RETURNS refcursor AS '
 DECLARE
    ref refcursor;
BEGIN
  if   $1=0   then
       UPDATE agenti SET  e='4', r='кировский', h='5', k='0', o='квартира', c='600', v='грн', d='2017-01-29T16:53:00.000Z', d_x='2017-01-30T09:17:29.779Z', z='{"1":1}', g='Бизнес' WHERE id = 168 ;
  else 
       INSERT INTO agenti (id,t1,e,r,h,k,o,c,v,d,d_x,p,s,z,g) VALUES (168, '0951510065', '4', 'Шевченковский', '5', '0', 'квартира', '600', 'грн', '2017-01-29T16:53:00.000Z', '2017-01-30T09:17:29.779Z', 0, 0, '{"1":1}', 'Бизнес'); ;
  end if;

   RETURN ref;
END;
' LANGUAGE plpgsql;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question