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

emacs sql-mode
emacs database
emacs sql-mode indent
emacs sqlite
postgresql lsp
emacs unable to locate sql program sqlite
org-mode database

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?

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; -*-

Sql Mode, This page is home of SQL mode for Emacs and XEmacs. Overview; Related Type M-x sql-help RET to read the online help. If you only work on one database, you might prefer not to confirm the default user, password, database, etc. settings. It saves the history in a separate file for each SQL “product”. You can type the SQL command directly into the SQLi buffer to execute or compose the command in the SQL buffer, select it and then call the command sql-send-region (bound to C-c C-r by default) to execute or sql-send-buffer (bound to C-c C-b by default) to execute all the buffer.

This is also an option, a comment on the first line in a file.

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

See http://stackoverflow.com/a/18118619/714357

sql.el --- specialized comint.el for SQL interpreters ;; Copyright (C , SqlMode ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can The interactive mode had to provide a command-line ;; history; the other mode had (interactive) ;; (sql-set-product 'xyz)) ;; 7) Add an autoloaded SQLi function. ;; ;; :type 'string :group 'SQL) (defcustom sql-database "" "*Default database. ‘sql-upcase-mode’ processes all inserted text; so it not only upcases keywords as you type, but it will upcase all keywords in any text you yank into the buffer (so to reformat existing SQL, you can simply kill it and yank it into a SqlMode buffer – although commands to upcase a SqlMode buffer or region are also provided).

How to set the default type as postgresql after startup emacs? What needs to be put in .emacs?

All you need is:

(setq sql-product 'postgres)

n.b. This approach does not necessitate that sql.el already be loaded.

SQL Mode Documentation, Instead, put a line in either your .emacs file, or the file $HOME/.sql-mode, as follows: (setq If no database is supplied, the default (master) database is simply used. require you to type them in on each invocation of either sql-batch-mode or  Modify Default Backup location in SQL Server on Linux. In the previous step, we modified the default data and log file locations. Database administrators may need to change the default path of the backup drive as well.

Setup Emacs as an SQL Database client - Part 1, Emacs's SQLi mode can be a better replacement for the default sql-***-login-​params where *** can be one of the database type that you want, for example Create another file named my-password.el.gpg , make sure that it  You’ll be prompted for username, database, password and host and then you’ll be dropped in a buffer dedicated to the connection you’ve specified. Apart from being able to run all sorts of SQL in that buffer you’ll also be able to send to it SQL from .sql files you’re editing in Emacs.

emacs/sql.el at master · emacs-mirror/emacs · GitHub, Find file Copy path. emacs/lisp/progmodes/sql.el. Find file Copy history; the other mode had to provide "send region/buffer to SQL (sql-set-product-feature '​xyz. ;; :font- 4) Define the interactive command interpreter for the database :​type 'sql-login-params "Default port for connecting to a MySQL or Postgres server.". The first element is a regex string, the second is a mode name (of type symbol). Emacs tries to match the first line of a file to values in magic-mode-alist. If there's a match, it sets the buffer to that mode. How Emacs Determines Which Major Mode to Load. Emacs determines what mode to activate by the following mechanisms, in order.

emacs-release/sql.elc at master · jwiegley/emacs-release · GitHub, This file uses dynamic docstrings, first added in Emacs 19.29. :risky t sql-​database #[0 "\300\207" [#1#] 1 "\n\n(fn)"] "Default database. :font-lock sql-​mode-informix-font-lock-keywords :sqli-program sql-informix-program :sqli-​options :type alist :key-type (string :tag "Connection") :value-type set group (​const :tag "Product"  This topic describes how to view or change the database by using SQL Server Management Studio or Transact-SQL. A recovery model is a database property that controls how transactions are logged, whether the transaction log requires (and allows) backing up, and what kinds of restore operations are available.