psql 定义变量

DO $$
DECLARE myvar integer;
BEGIN
    SELECT 5 INTO myvar;

    DROP TABLE IF EXISTS tmp_table;
    CREATE TABLE tmp_table AS
    SELECT * FROM yourtable WHERE   id = myvar;
END $$;

SELECT * FROM tmp_table;

 

posted on 2022-08-22 15:38  空明流光  阅读(65)  评论(0编辑  收藏  举报

导航