Re: Fix PQport to never return NULL if the connection is valid

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix PQport to never return NULL if the connection is valid
Date: 2025-05-08 20:01:18
Message-ID: CA+mi_8aaQdULFYo6jDtG+aUzfNmyuitrqNAhx_N_BrCu-beeCw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I looked a bit more into the meaning of the port="" setting. The docs
for the port parameter / PGPORT env var
<https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-PORT>
say:

An empty string, or an empty item in a comma-separated list,
specifies the default port number established when
PostgreSQL was built

Thus I understand that the return value of PQport wants to reflect
this behaviour, therefore the value "" is legitimate and it's up to
the client to figure out how the libpq was built (PQconndefaults may
tell that).

Please find attached a new patch that doesn't change the behaviour and
just makes sure to not return NULL in case no info is available in
'conn->connhost'.

Cheers

-- Daniele

Attachment Content-Type Size
0001-Fix-PQport-to-never-return-NULL-unless-the-connectio.patch text/x-patch 1016 bytes

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-05-08 20:07:25 Re: [PATCH] Fix missing comma in Requires.private with a Make macro
Previous Message Yasir 2025-05-08 19:57:19 Re: Valgrind - showing memory leaks