I have a question regarding connecting to a sql database programmatically. Ideally I would like to have a function with similar functionality to the sql-postgres but instead of interactively prompting me for each part of the connection string, I would just like to programmatically provide all of the arguments.

I seemed to make some progress by setting the defaults the database uses as follows:

    (setq sql-user url-user)
    (setq sql-server "localhost") 
    (setq sql-database "myDatabase")
    (setq sql-port db-port)
    (setq sql-password my-password)
    (call-interactively #'sql-postgres)

This gets me 90% the way there. The only thing missing is the prompt still asks me for my password and wont take the default I set. I was looking around for a workaround but I could't seem to figure it out. If there is a better way to go about this problem I would be glad to hear ideas.

1 Answer 1


This is a duplicate of this S.O. question:


Your problem is that you cannot include the password as part of the psql command, so this (generic) functionality of Emacs' SQL support is not applicable to postgres.

Refer to the duplicate Q&A for lots of discussion and options.

See also:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.