如何根据查询的结果退出 psql
How to exit psql depending on the outcome of a query
cd C:\Program Files\PostgreSQL\bin
psql.exe -v v1="test" -h localhost -d postgres -U postgres -p 5432 -a -q -f /elan/Validate_files.sql
....
Select case when current_date-date(a.timestamp_1) >1 then 'No' Else 'Yes' End as Check
from elan.temp_file_names a
where a.filename not in (select b.filename from elan.temp_previous_names b)
and position('ELAN_CLAIMS' in a.filename)>1 order by timestamp_1 desc
\gset
如果 Check 为 No,我想结束 psql 进程,我该怎么做?
将 CASE
表达式更改为 return a boolean
:
CASE WHEN ... THEN TRUE ELSE FALSE
END AS check ... \gset
然后使用\if
:
\if :check
\q
\endif
cd C:\Program Files\PostgreSQL\bin
psql.exe -v v1="test" -h localhost -d postgres -U postgres -p 5432 -a -q -f /elan/Validate_files.sql
....
Select case when current_date-date(a.timestamp_1) >1 then 'No' Else 'Yes' End as Check
from elan.temp_file_names a
where a.filename not in (select b.filename from elan.temp_previous_names b)
and position('ELAN_CLAIMS' in a.filename)>1 order by timestamp_1 desc
\gset
如果 Check 为 No,我想结束 psql 进程,我该怎么做?
将 CASE
表达式更改为 return a boolean
:
CASE WHEN ... THEN TRUE ELSE FALSE
END AS check ... \gset
然后使用\if
:
\if :check
\q
\endif