[PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

Started by Ian Lawrence Barwick2 months ago11 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

This thread has been committed, so CI has stopped here. Anything below is the last result it produced.

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253102
psql -h localhost -U postgres

Built from patchset v5 (message #5), July 28, 2026 at 10:32 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t253102_5 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t253102_5 && git checkout t253102_5

Patchset v5 (message #5) is on t253102_5

Jump to latest
#1Ian Lawrence Barwick
barwick@gmail.com

Hi

It was noted here [1]/messages/by-id/allgZ34IHVFZo35b@paquier.xyz that we have the undocumented SQL function
"getdatabaseencoding()", used mainly in regression tests and a couple
of psql queries. While considering a documentation patch, it occurred
to me that it's a horrible function name which doesn't look like other
public functions, and we already have "pg_client_encoding()", so why not
rename it to match that while we're at it?

The only minor niggle I can see is that psql uses "getdatabaseencoding()"
for tab completion of collation names, and it looks like it would be
tricky/ugly to try and shoehorn in version-dependent queries for backwards
compatibility, but we can just substitute "current_setting('server_encoding')".

[1]: /messages/by-id/allgZ34IHVFZo35b@paquier.xyz

Regards

Ian Barwick

Attachments:

v1-0001-Rename-getdatabaseencoding-to-pg_database_encodin.patchapplication/octet-stream; name=v1-0001-Rename-getdatabaseencoding-to-pg_database_encodin.patchDownload+105-82
#2Daniel Gustafsson
daniel@yesql.se
In reply to: Ian Lawrence Barwick (#1)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

On 17 Jul 2026, at 08:44, Ian Lawrence Barwick <barwick@gmail.com> wrote:

It was noted here [1] that we have the undocumented SQL function
"getdatabaseencoding()", used mainly in regression tests and a couple
of psql queries. While considering a documentation patch, it occurred
to me that it's a horrible function name which doesn't look like other
public functions, and we already have "pg_client_encoding()", so why not
rename it to match that while we're at it?

This function seems to be referred to in extensions, how about adding keeping
the existin name and adding the new name as an alias? It would keep existing
code from breaking and cause less churn in the code.

--
Daniel Gustafsson

#3Thom Brown
thom@linux.com
In reply to: Daniel Gustafsson (#2)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

On Fri, 17 Jul 2026, 08:24 Daniel Gustafsson, <daniel@yesql.se> wrote:

On 17 Jul 2026, at 08:44, Ian Lawrence Barwick <barwick@gmail.com>

wrote:

It was noted here [1] that we have the undocumented SQL function
"getdatabaseencoding()", used mainly in regression tests and a couple
of psql queries. While considering a documentation patch, it occurred
to me that it's a horrible function name which doesn't look like other
public functions, and we already have "pg_client_encoding()", so why not
rename it to match that while we're at it?

This function seems to be referred to in extensions, how about adding
keeping
the existin name and adding the new name as an alias? It would keep
existing
code from breaking and cause less churn in the code.

Why don't extensions use current_setting('server_encoding')?

Thom

Show quoted text
#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Daniel Gustafsson (#2)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

Daniel Gustafsson <daniel@yesql.se> writes:

On 17 Jul 2026, at 08:44, Ian Lawrence Barwick <barwick@gmail.com> wrote:
It was noted here [1] that we have the undocumented SQL function
"getdatabaseencoding()", used mainly in regression tests and a couple
of psql queries. While considering a documentation patch, it occurred
to me that it's a horrible function name which doesn't look like other
public functions, and we already have "pg_client_encoding()", so why not
rename it to match that while we're at it?

This function seems to be referred to in extensions, how about adding keeping
the existin name and adding the new name as an alias? It would keep existing
code from breaking and cause less churn in the code.

Yeah, the odds that we would remove the old name (without a multi-year
deprecation period) are zero, full stop.

However, I can't really get excited about this proposal in the first
place. There are plenty of ugly and inconsistent names in Postgres,
and an enormous amount of more-valuable work to do.

regards, tom lane

#5Ian Lawrence Barwick
barwick@gmail.com
In reply to: Tom Lane (#4)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

2026年7月17日(金) 23:29 Tom Lane <tgl@sss.pgh.pa.us>:

Daniel Gustafsson <daniel@yesql.se> writes:

On 17 Jul 2026, at 08:44, Ian Lawrence Barwick <barwick@gmail.com> wrote:
It was noted here [1] that we have the undocumented SQL function
"getdatabaseencoding()", used mainly in regression tests and a couple
of psql queries. While considering a documentation patch, it occurred
to me that it's a horrible function name which doesn't look like other
public functions, and we already have "pg_client_encoding()", so why not
rename it to match that while we're at it?

This function seems to be referred to in extensions, how about adding keeping
the existin name and adding the new name as an alias? It would keep existing
code from breaking and cause less churn in the code.

Yeah, the odds that we would remove the old name (without a multi-year
deprecation period) are zero, full stop.

However, I can't really get excited about this proposal in the first
place. There are plenty of ugly and inconsistent names in Postgres,
and an enormous amount of more-valuable work to do.

Makes sense.

Here's a patch to at least document it, in the table "Other String
Functions and Operators"
(as "pg_client_encoding()" is already there).

Regards

Ian Barwick

Attachments:

t253102_5
v1-0001-Document-getdatabaseencoding.patchtext/x-patch; charset=US-ASCII; name=v1-0001-Document-getdatabaseencoding.patchDownload+17-1
#6Thom Brown
thom@linux.com
In reply to: Ian Lawrence Barwick (#5)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

On Sat, 18 Jul 2026, 06:05 Ian Lawrence Barwick, <barwick@gmail.com> wrote:

2026年7月17日(金) 23:29 Tom Lane <tgl@sss.pgh.pa.us>:

Daniel Gustafsson <daniel@yesql.se> writes:

On 17 Jul 2026, at 08:44, Ian Lawrence Barwick <barwick@gmail.com>

wrote:

It was noted here [1] that we have the undocumented SQL function
"getdatabaseencoding()", used mainly in regression tests and a couple
of psql queries. While considering a documentation patch, it occurred
to me that it's a horrible function name which doesn't look like other
public functions, and we already have "pg_client_encoding()", so why

not

rename it to match that while we're at it?

This function seems to be referred to in extensions, how about adding

keeping

the existin name and adding the new name as an alias? It would keep

existing

code from breaking and cause less churn in the code.

Yeah, the odds that we would remove the old name (without a multi-year
deprecation period) are zero, full stop.

However, I can't really get excited about this proposal in the first
place. There are plenty of ugly and inconsistent names in Postgres,
and an enormous amount of more-valuable work to do.

Makes sense.

Here's a patch to at least document it, in the table "Other String
Functions and Operators"
(as "pg_client_encoding()" is already there).

I would go in the opposite direction; announce its deprecation, and mention
the alternative in the release notes. Surely we don't want to make it more
difficult to get rid of?

Thom

Show quoted text
#7Ian Lawrence Barwick
barwick@gmail.com
In reply to: Thom Brown (#6)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

2026年7月18日(土) 16:57 Thom Brown <thom@linux.com>:

On Sat, 18 Jul 2026, 06:05 Ian Lawrence Barwick, <barwick@gmail.com> wrote:

2026年7月17日(金) 23:29 Tom Lane <tgl@sss.pgh.pa.us>:

Daniel Gustafsson <daniel@yesql.se> writes:

On 17 Jul 2026, at 08:44, Ian Lawrence Barwick <barwick@gmail.com> wrote:
It was noted here [1] that we have the undocumented SQL function
"getdatabaseencoding()", used mainly in regression tests and a couple
of psql queries. While considering a documentation patch, it occurred
to me that it's a horrible function name which doesn't look like other
public functions, and we already have "pg_client_encoding()", so why not
rename it to match that while we're at it?

This function seems to be referred to in extensions, how about adding keeping
the existin name and adding the new name as an alias? It would keep existing
code from breaking and cause less churn in the code.

Yeah, the odds that we would remove the old name (without a multi-year
deprecation period) are zero, full stop.

However, I can't really get excited about this proposal in the first
place. There are plenty of ugly and inconsistent names in Postgres,
and an enormous amount of more-valuable work to do.

Makes sense.

Here's a patch to at least document it, in the table "Other String
Functions and Operators"
(as "pg_client_encoding()" is already there).

I would go in the opposite direction; announce its deprecation, and mention the alternative in the release notes. Surely we don't want to make it more difficult to get rid of?

There doesn't seem to be consensus to do that. Either way, documenting its
existence would be useful to have, IMO.

Regards

Ian Barwick

#8Daniel Gustafsson
daniel@yesql.se
In reply to: Ian Lawrence Barwick (#7)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

On 24 Jul 2026, at 03:29, Ian Lawrence Barwick <barwick@gmail.com> wrote:

Either way, documenting its existence would be useful to have, IMO.

I can't really come up with an argument for not documenting it, so unless there
are objections I'll apply the docs patch.

--
Daniel Gustafsson

#9surya poondla
suryapoondla4@gmail.com
In reply to: Ian Lawrence Barwick (#1)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

Hi All,

+1 for documenting it.

I took a look at the patch, it applies cleanly to master and the resulting
SGML is well-formed.

The description text mirrors pg_client_encoding()'s existing entry
("Returns current client encoding name."), which seems right to me for
consistency. The declared "name" return type matches pg_proc.dat, too.

It might also be worth mentioning in the description that this returns the
server encoding, i.e. the same value as current_setting('server_encoding').
Feel free to ignore if you'd rather keep the entry minimal.

Regards,
Surya Poondla

#10Daniel Gustafsson
daniel@yesql.se
In reply to: surya poondla (#9)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

On 27 Jul 2026, at 20:10, surya poondla <suryapoondla4@gmail.com> wrote:

+1 for documenting it.

Pushed.

It might also be worth mentioning in the description that this returns the server encoding, i.e. the same value as current_setting('server_encoding').
Feel free to ignore if you'd rather keep the entry minimal.

That could be applied in many places, so I opted out of doing in this single
instance and instead went with consistency with the client encoding function.

--
Daniel Gustafsson

#11Ian Lawrence Barwick
barwick@gmail.com
In reply to: Daniel Gustafsson (#10)
Re: [PATCH] Rename "getdatabaseencoding()" to "pg_database_encoding()", and document

2026年7月29日(水) 19:50 Daniel Gustafsson <daniel@yesql.se>:

On 27 Jul 2026, at 20:10, surya poondla <suryapoondla4@gmail.com> wrote:

+1 for documenting it.

Pushed.

Thanks!

It might also be worth mentioning in the description that this returns the server encoding, i.e. the same value as current_setting('server_encoding').
Feel free to ignore if you'd rather keep the entry minimal.

That could be applied in many places, so I opted out of doing in this single
instance and instead went with consistency with the client encoding function.

Yup, if at all that would be a separate operation.

Regards

Ian Barwick