UPDATE a whole row in PL/pgSQL

前端 未结 3 1906
南旧
南旧 2021-01-19 06:33

I have plpgsql function:

CREATE OR REPLACE FUNCTION test() RETURNS VOID AS
$$
DECLARE
    my_row my_table%ROWTYPE;
BEGIN
    SELECT * INTO my_row FROM my_tab         


        
3条回答
  •  不知归路
    2021-01-19 07:10

    yes, its possible to update / append the row-type variable,

    CREATE OR REPLACE FUNCTION test() RETURNS VOID AS $$
    DECLARE    
             my_row my_table%ROWTYPE;
    BEGIN
             SELECT * INTO my_row FROM my_table WHERE id='1';
             my_row.date := now(); 
             raise notice  'date  : %; ',my_row.date;
    END;
    $$ LANGUAGE plpgsql;
    

    here the raise notice will display the today's date only.

    but this will not update the column date in my_table.

提交回复
热议问题