How to declare a variable in a PostgreSQL query

后端 未结 12 1529
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 09:34

How do I declare a variable for use in a PostgreSQL 8.3 query?

In MS SQL Server I can do this:

DECLARE @myvar INT
SET @myvar = 5

SELECT *
FROM somew         


        
12条回答
  •  生来不讨喜
    2020-11-22 09:40

    Using a Temp Table outside of pl/PgSQL

    Outside of using pl/pgsql or other pl/* language as suggested, this is the only other possibility I could think of.

    begin;
    select 5::int as var into temp table myvar;
    select *
      from somewhere s, myvar v
     where s.something = v.var;
    commit;
    

提交回复
热议问题