I had this problem, but the solution was a bit different than the others listed. I am running PostrgreSQL on my Mac via Postgres.app. I had originally installed just the build with version 15 in it, but upgraded to the one with multiple versions in it so I could migrate my data from version 15 to 17. The version 15 command-line tools were in my path, so I was using the version 15 sql to connect to the version 17 server.
I re-ran the command to set up the command tools and restarted my terminal, and all is well now.