Re: pg_get_databasebyid(oid)

From: Ibrar Ahmed <ibrar(dot)ahmad(at)gmail(dot)com>
To: Sergei Kornilov <sk(at)zsrv(dot)org>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, alexey(dot)lesovsky(at)dataegret(dot)com
Subject: Re: pg_get_databasebyid(oid)
Date: 2019-08-29 10:47:40
Message-ID: CALtqXTcDaetsPB3+qC-yUZESXGY5mQ6wLx_h-CxLMH45HZnqWA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Aug 29, 2019 at 3:16 PM Sergei Kornilov <sk(at)zsrv(dot)org> wrote:

> Hello
>
> > Is there a need for this function for the user?
>
> This was feature request from user. I got such comment:
>
> This function is useful when working with pg_stat_statements. For
> obtaining a databаse name for particular query you need to join pg_database
> relation, but for obtaining an username you just need pg_get_userbyid(). So
> it will be useful not to join extra relation and get a database name using
> the similar function - pg_get_databasebyid().
>
> regards, Sergei
>

Hi,
I think its a user request and don't require to be in the core of
PostgreSQL.
A simple SQL function can fulfill the requirement of the user.

CREATE OR REPLACE FUNCTION pg_get_databasebyid(dboid integer) RETURNS name
AS $$

SELECT datname from pg_database WHERE oid = dboid;
$$ LANGUAGE SQL;

--
Ibrar Ahmed

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2019-08-29 11:12:00 Re: no mailing list hits in google
Previous Message Sergei Kornilov 2019-08-29 10:16:25 Re: pg_get_databasebyid(oid)