简体   繁体   English

与SQL Server的If Exists等效的Postgres(

[英]What is the Postgres equivalent of SQL Server's If Exists(

I have a T-SQL query I would like to be able to use in Postgres. 我有一个想在Postgres中使用的T-SQL查询。 I'm new to Postgres and would like to know if the If Exists is possible as well as the Print or what the equivalents would be. 我是Postgres的新手,我想知道If Exists以及Print或等效If Exists是否可行。

Basically it is just checking to see if there is any info in a table and if there is then it calls a stored procedure, if not it posts nothing to report in the logs, that part isn't really needed but I would like to know the print if possible. 基本上,它只是检查表中是否有任何信息,是否存在,然后调用存储过程,如果没有,则在日志中不报告任何内容,这部分不是真正需要的,但我想知道尽可能打印。

IF Exists(Select * from [mytable]
Having Count(*) > 0)

EXEC sp_someprocedure
ELSE
PRINT 'Table Empty: Nothing to report.'

Sure does, for example: 当然可以,例如:

do $$begin
if exists (select * from yourtable) then
    perform your_function();
else
    raise notice 'nothing to report';
end if;
end$$;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM