I have the following configuration in emacs init files to set a variable (user) to the current Unix login user:
(setq sql-postgres-login-params
`((user :default ,user-login-name)
(database :default ,user-login-name)
(server :default "127.0.0.1")
(port :default 5432)))
With this, I was able to login into PostgreSQL databases with the Unix login user as the default database user. However, this stops working when the Unix user name contains dashes -, and needs to be double-quoted. For example, in PostgreSQL, when the unix user is myuser, it's OK to use it directly as the database user name. However, when the user name is my-user, it needs to be quoted as "my-user" to be used as a user name (or database name). My question is:
How can I make the user-login-name in the above example quoted?
e.g. if ,user-login-name is my-user, how do I use "my-user" instead?
I am not familiar with elisp, and the below is the best I can come up with (concatenating with "\""s). But database login still fails.
(setq sql-postgres-login-params
`((user :default ,(concat "\"" user-login-name "\"") )
(database :default ,(concat "\"" user-login-name "\"") )
(server :default "127.0.0.1")
(port :default 5432)))
psqlon the command line, for instance, you would saypsql --username='"my-user"'?*Messages*buffer? If so, please copy it to the question.psqlcommand, that would be very useful.sql-postgres, so I've made some edits. FYI as far as elisp and strings go, there's nothing wrong with yourconcatusage (or you could alternatively useformat). I suspect none of that is actually relevant to your problem, though (and indeed that it's potentially causing additional problems to add those quotes in that context).psqlworks fine on the command line. And there was no errors in Message. Adding the code in your answer fixed the problem.