How to insert data into table using stored procedures in postgresql

后端 未结 4 1018
猫巷女王i
猫巷女王i 2020-12-29 05:39
CREATE TABLE app_for_leave
(
  sno integer NOT NULL,
  eid integer,
  ename varchar(20),
  sd date,
  ed date,
  sid integer,
  status boolean DEFAULT false,
  CONST         


        
4条回答
  •  离开以前
    2020-12-29 06:06

    Starting from PostgreSQL 11 you could create stored procedures and invoke them using CALL:

    CREATE PROCEDURE MyInsert(_sno integer, _eid integer, _sd date,
                              _ed date, _sid integer, _status boolean)
    LANGUAGE SQL
    AS $$
        INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status)
        VALUES(_sno, _eid, _sd, _ed, _sid, _status);   
    $$;
    
    CALL MyInsert(1,101,'2013-04-04','2013-04-04',2,'f' );
    

    Plus it allows to handle transaction

    SQL Stored Procedures

    PostgreSQL 11 introduces SQL stored procedures that allow users to use embedded transactions (i.e. BEGIN, COMMIT/ROLLBACK) within a procedure. Procedures can be created using the CREATE PROCEDURE command and executed using the CALL command.

提交回复
热议问题