2

Is it possible with easy syntax like MS SQL Server do

SELECT HOST_NAME()

in postgresql 9.3.2? I have read some articles but no result !

postgreat
  • 545
  • 3
  • 7
  • 16
  • http://stackoverflow.com/questions/5598517/find-the-host-name-and-port-using-psql-commands – vijaykumar Feb 18 '14 at 04:21
  • @vijay4vijju I already read the article before, but I'm not found the answer – postgreat Feb 18 '14 at 04:58
  • @ntalbs that's the ip and the port, not the hostname. Still not the answer that i'm looking for – postgreat Feb 18 '14 at 05:00
  • 1
    Which hostname do you want? The one where Postgres is running or the one from the current client? –  Feb 18 '14 at 06:50
  • @a_horse_with_no_name current client – postgreat Feb 18 '14 at 08:13
  • Out of curiosity, what would you want the behavior to be if the IP address of the client has multiple hostnames defined in DNS? I have seen dozens of hostnames associated with a single IP address. – kgrittn Mar 13 '14 at 22:40

1 Answers1

4

No, the default build doesn't have that. It is easy however to extend PostgreSQL with new native functions and someone already did it: http://pgxn.org/dist/hostname/ .

Another way would be to install an additional db language (PostgreSQL is great like that - you have the option of using arbitrary languages instead of pl/pgsql) and use the language's own functions to do that. There are e.g. pl/python (http://www.postgresql.org/docs/9.1/static/plpython-funcs.html) and pl/perl (http://www.postgresql.org/docs/9.1/static/plperl-trusted.html -- see also the discussion about trusted and untrusted languages).

Ivan Voras
  • 1,895
  • 1
  • 13
  • 20