0

I have a question. so I have a query into "txt". txt is a column of one of my table(opt_xel_views) and i want to know how to execute the query that is in txt.

Here is my code

Kheira
  • 7
  • 7
  • You have several errors. requete must be declared in "DECLARE" section. and your select query "SELECT txt INTO ..." is using a nonsense WHERE clause based on r which is not part of the query. – mnesarco Jul 15 '21 at 20:28
  • @mnesarco no I said i added this in my function so I added it correctly there is no error dont worry – Kheira Jul 15 '21 at 21:13

1 Answers1

0

There is not enough context, but probably what you want is:

CREATE OR REPLACE FUNCTION opt_z00_batch(psBatNam VARCHAR(70)) RETURNS void AS $$
DECLARE
    r record;
    
BEGIN
    FOR r IN
    
        Select y8_name,y8_order,y8_step,y8_query,y8_count, y8_comment, txt 
        From   opt_xel_batchs 
        inner join opt_xel_views
        On     y8_query = id 
        Where  y8_name = psBatNam
        Order by y8_order
    LOOP

      execute r.txt;

      INSERT INTO opt_xel_log(z_log_dat, z_bat_nam, z_bat_stp, z_bat_ord, z_bat_com, a_nbr_upd) values(current_timestamp, psBatNam , r.y8_query, r.y8_order, r.y8_comment, 1);
     

    
    END LOOP;
END;
$$ LANGUAGE plpgsql;   
mnesarco
  • 2,619
  • 23
  • 31
  • i m sorry, no this cant work because tkt is from the table opt_xel_batchs not opt_xel_batchs. r is a rowtype of the table opt_xel_batchs – Kheira Jul 15 '21 at 21:12
  • You can use record type which is generic. Updated the example. – mnesarco Jul 15 '21 at 21:21