Question

I am trying to run some code in Aginity for Netezza without putting it in a stored procedure, but I can't get the syntax right. Here is some sample code below. It gives errors like "Found "DECLARE" (at char 1) expecting a keyword." If I put the code in a stored procedure, it will run fine.

declare
cnt integer;
rVend record;

begin

FOR rVend in select vend_skey, vend_lvl_1_cd from dim_vend loop
    select count(*) into cnt
    from dim_vend 
    where vend_lvl_1_cd = rVend.vend_lvl_1_cd and vend_skey < rVend.vend_skey;

    if cnt > 0 then
        update dim_vend
        set to_delete = 1 where vend_skey = rVend.vend_skey;
    end if;

end loop;

end;
Was it helpful?

Solution

The problem is that Netezza does not allow variables to be used outside of stored procedures.

If you use Aginity Workbench to query your database, you can use "parameter substitution" as a workaround. This is basically a find-and-replace that Workbench implements before running the SQL. The syntax is $ParamName.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top