notebook
  • coding
    • 2016/11/03_sql optimization principle
    • 2017/08/19_docker for gitlab install
    • 2018/02/15_dotnet core
    • 2018/06/16_vs key
    • 2018/09/12_network protocol
    • 2018/10/23_Distributed service framework
    • 2018/10/24_knowledge
    • 2018/11/03_environment deployment
    • 2018/11/23_release nuget package
    • 2018/12/04_free https
    • 2020/04/29_EFmigrationCmdLine
    • 2020/12/18_push docker image to aws
    • 2022/12/16_HttpClient-multipart
    • 2023/02/17_postgresSql-function
    • 2023/03/09_dockerImages_deploy
    • 2023/04/08_word-helper
    • 2023/11/08_tableAndRowLock
  • living
  • playing
Powered by GitBook
On this page

Was this helpful?

  1. coding

2023/02/17_postgresSql-function

CREATE OR REPLACE FUNCTION query_result(IN inputDate text) RETURNS TABLE 
(aa varchar(64),ss varchar(64),n timestamp)AS $$

declare counter integer:=1;
declare startTime timestamp:=to_timestamp(inputDate, 'yyyy-MM-dd hh24:mi:ss');
declare days integer:=(select extract (day from date_trunc('month', startTime)+ interval '1 month'- interval '1 day'));

begin
	
	while counter<days loop
        counter := counter + 1;
       	return query
    	select  distinct xx,xx,xx from xxx   where  condition1 and
    	and xxx >=to_timestamp(to_char(startTime,'yyyy-mm-')||to_char(counter,'00') ||' 00:00:00','yyyy-MM-dd hh24:mi:ss' )
    	and xxx <=to_timestamp(to_char(startTime,'yyyy-mm-')||to_char(counter,'00') ||' 23:59:59','yyyy-MM-dd hh24:mi:ss' );
    end loop;
END;
$$ LANGUAGE plpgsql STABLE;

SELECT * FROM query_result('2023-02');              
Previous2022/12/16_HttpClient-multipartNext2023/03/09_dockerImages_deploy

Last updated 2 years ago

Was this helpful?