我正在使用pgScript,並且必須提取有關數據庫所在的服務器的信息。我知道我可以得到IP地址和端口,但我需要服務器的主機名。目前,我有:Postgresql解析pgScript變量以刪除行
declare @machineName;
declare @I;
set @I = 0;
create temp table foo (t text);
copy foo from '/etc/hosts';
set @machineName =
select * from foo;
print @machineName;
set @machineNameCount = select count(*) from foo;
我回去:
("127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4")
("::1 localhost localhost.localdomain localhost6 localhost6.localdomain6")
("xx.xx.x.xx HOSTNAME")
我知道我有三條線的工作,在這種情況下,所以我要@machineName使用在運行一個while循環@ machineNameCount,我只想刪除其中包含「127.0.0.1」或「:: 1」的任何行,但我無法弄清楚如何解析這些行。如果我可以看到一行是否包含我可以刪除的行。有任何想法嗎?
我不知道如何從pgscript運行bash命令。我必須做所有這些包含在一個pgscript中,我似乎在解析pgscript可以做的事情上相當有限。 –