Search code examples
emacselispdot-emacs

emacs: how to set the default database type for a sql file in SQL mode


In SQL mode, we could select the product type such posgres, mysql, oracle etc, and the default one is ANSI, how to set the default type as postgresql after startup emacs? What needs to be put in .emacs?


Solution

  • SQL mode has sql-set-product function which is used to set the product.

    C-h f sql-set-product RET lists the details of the function.

    sql-set-product is an interactive compiled Lisp function.
    
    (sql-set-product PRODUCT)
    
    Set `sql-product' to PRODUCT and enable appropriate highlighting.
    

    So, you can add

    (sql-set-product 'postgres)
    

    to your .emacs file to make it as default.

    At any point of time, if you want to change it mysql or something else, you can use

    M-x sql-set-product RET mysql RET
    

    Alternatively, as shown in @teaforthecat's answer, the product can be set from a comment on the first line

    -- -*- mode: sql; sql-product: mysql; -*-