How do I declare variables in pgAdmin

前端 未结 3 1295
梦谈多话
梦谈多话 2021-02-20 05:38

If I am in the psql terminal then I can declare and use a variable like this:

\\set message_id soifsdaofisd.gmail.com;
select * from emails where message_id = \'         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 05:53

    An alternative is to create a view.

    -- create view to store variable list
    create view script_variables as select 'soifsdaofisd.gmail.com' as message_id;
    -- run your script
    select * from emails where message_id = (select message_id from script_variables);
    -- clean up 
    drop view script_variables; 
    

提交回复
热议问题