In PostgreSQL, we can use the pg_client_encoding()
function to get the current client encoding name.
Example
Here’s an example to demonstrate:
SELECT pg_client_encoding();
Result:
pg_client_encoding
--------------------
UTF8
So the function doesn’t require (or accept) any arguments. We simply call the function by name, and it returns the result.
In this case, the client was using UTF8 and so that’s what was returned.
Passing Arguments
As mentioned, the pg_client_encoding()
function doesn’t accept any arguments. Here’s what happens if I try to pass an argument:
SELECT pg_client_encoding(10);
Result:
ERROR: function pg_client_encoding(integer) does not exist
LINE 1: SELECT pg_client_encoding(10);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Basically this just tells us that PostgreSQL doesn’t have a function of that name that accepts an argument of that type. It’s a common error when calling functions with the wrong argument type. But in this case the function doesn’t accept any arguments, and so we’ll get a similar error regardless of the argument’s type.