zoukankan      html  css  js  c++  java
  • [PostgreSql]PostgreSql调用函数及用IF EXISTS判断表是否存在

    1.创建一个函数function1

    -- FUNCTION: public.function1(character varying, integer)
    
    -- DROP FUNCTION public.function1(character varying, integer);
    
    CREATE OR REPLACE FUNCTION public.function1(
        useridl character varying,
        groupidl integer)
    RETURNS TABLE(vehicle_id integer) 
        LANGUAGE 'plpgsql'
        COST 100
        VOLATILE 
        ROWS 1000
    AS $BODY$
    
    BEGIN
    -- Insert statements for procedure here
    RETURN QUERY
    select v.vehicle_id
    from mst_vehicle as v
    where v.deletef=0;
    END;
    
    $BODY$;
    
    ALTER FUNCTION public.function1(character varying, integer)
        OWNER TO postgres;

    2.在另一个函数function2中调用function1

    -- FUNCTION: public.function2(character varying,integer,timestamp without time zone)
    
    -- DROP FUNCTION public.function2(character varying,integer,timestamp without time zone);
    
    CREATE OR REPLACE FUNCTION public.function2(
        userIDl character varying,
        groupIDl integer,
        minVersionl timestamp without time zone)
    RETURNS TABLE(
    loading_info character varying(16)
     )
        LANGUAGE 'plpgsql'
        COST 100.0
    
    AS $function$
    
    BEGIN
    -- Insert statements for procedure here
    drop table IF EXISTS public.temp_ids;
    create table public.temp_ids(vehicle_id int);
    insert into public.temp_ids values(function1(userIDl,groupIDl));
    RETURN QUERY
        
    select 
    car.loading_info
    from dy_VehicleList
    
    drop table IF EXISTS public.temp_ids;
    
    END;
    
    $function$;
    
    ALTER FUNCTION public.function2(character varying,integer,timestamp without time zone)
        OWNER TO postgres;

    其中用IF EXISTS判断表是否存在,存在则删除

    DROP TABLE IF EXISTS tableName
  • 相关阅读:
    简单的三栏,文字多行居中效果 css原生
    目录
    HttpRunner使用
    测试职能
    缺陷
    SQL操作数据
    jmeter使用
    接口自动化理论引入
    接口自动化框架(Pytest,Allure,Yaml)
    jmeter 登陆--查询存在否-->新建客户-->查询存在否 + 压测
  • 原文地址:https://www.cnblogs.com/vickylinj/p/9668382.html
Copyright © 2011-2022 走看看