zoukankan      html  css  js  c++  java
  • PG数组类型使用

    数组遍历

    create or replace function func_test()
    returns integer
    language 'plpgsql'
    as
    $$
    declare 
        rec record;
        # 定义数组并初始化
        tmp_res varchar ARRAY:=ARRAY[''];
    begin
     	# 2.tbl_ua 只针对平级域
            for rec in select id from test where code = 3
        loop
    	    
            tmp_res=array_append(tmp_res,rec.id::varchar);
    
        end loop;
    	#    从第二个元素开始遍历
        for i in 2..array_length(tmp_res,1)
        loop
            update test4 set code='eda_'||code where code=tmp_res[i];
        end loop;
    

    数组遍历与赋值

    CREATE OR REPLACE FUNCTION func_test2() 
    RETURNS INTEGER 
    AS
    $BODY$
    DECLARE
    	data int[] := array[1,2,3];
    	i int;
    BEGIN
    	select array_agg(id) into data from test;
    	raise notice 'func_name = % ','func_test';
    	for i in 1..array_length(data,1) loop
    			raise notice 'data[%] = % ',i,data[i];
    	end loop;
    	
        RETURN 0;
    END;
    $BODY$
    LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
    
  • 相关阅读:
    Periodic Strings ( UVA
    Digit Counting ( UVA
    Molar mass ( UVA
    Score ( UVA
    Let the Balloon Rise (STL)
    Tree Recovery (STL)
    安卓simpleadapter问题
    安卓活跃手指问题
    python 问题记录
    设计模式笔记
  • 原文地址:https://www.cnblogs.com/yldf/p/11899979.html
Copyright © 2011-2022 走看看