Home Explore Blog CI



neovim

8th chunk of `runtime/doc/ft_sql.txt`
44366949c63dd2a8a815e5f06a1be526039faafaee23ec790000000100000fac
 change the schema of a cached table you can press <C-C>R, which
       clears the SQL completion cache.
     - NOTE: <Right> and <Left> have been designed to work while the
       completion window is active.  If the completion popup window is
       not active, a normal <Right> or <Left> will be executed.

Let's look at how we can build a SQL statement dynamically.  A select statement
requires a list of columns.  There are two ways to build a column list using
the SQL completion plugin. >
    One column at a time:
<       1. After typing SELECT press <C-C>t to display a list of tables.
	2. Choose a table from the list.
	3. Press <Right> to display a list of columns.
	4. Choose the column from the list and press enter.
	5. Enter a "," and press <C-C>c.  Generating a column list
	   generally requires having the cursor on a table name.  The plugin
	   uses this name to determine what table to retrieve the column list.
	   In this step, since we are pressing <C-C>c without the cursor
	   on a table name the column list displayed will be for the previous
	   table.  Choose a different column and move on.
	6. Repeat step 5 as often as necessary. >
    All columns for a table:
<	1. After typing SELECT press <C-C>t to display a list of tables.
	2. Highlight the table you need the column list for.
	3. Press <Enter> to choose the table from the list.
	4. Press <C-C>l to request a comma-separated list of all columns
	   for this table.
	5. Based on the table name chosen in step 3, the plugin attempts to
	   decide on a reasonable table alias.	You are then prompted to
	   either accept of change the alias.  Press OK.
	6. The table name is replaced with the column list of the table is
	   replaced with the comma separate list of columns with the alias
	   prepended to each of the columns.
	7. Step 3 and 4 can be replaced by pressing <C-C>L, which has
	   a <C-Y> embedded in the map to choose the currently highlighted
	   table in the list.

There is a special provision when writing select statements.  Consider the
following statement: >
     select *
       from customer c,
	    contact cn,
	    department as dp,
	    employee e,
	    site_options so
      where c.

In INSERT mode after typing the final "c." which is an alias for the
"customer" table, you can press either <C-C>c or <C-X><C-O>.  This will
popup a list of columns for the customer table.  It does this by looking back
to the beginning of the select statement and finding a list of the tables
specified in the FROM clause.  In this case it notes that in the string
"customer c", "c" is an alias for the customer table.  The optional "AS"
keyword is also supported, "customer AS c".


 4.3.3 Procedure Completion:			*sql-completion-procedures*

Similar to the table list, <C-C>p, will display a list of stored
procedures stored within the database.

 4.3.4 View Completion:				*sql-completion-views*

Similar to the table list, <C-C>v, will display a list of views in the
database.


------------------------------------------------------------------------------
4.4 Completion Customization			*sql-completion-customization*

The SQL completion plugin can be customized through various options set in
your |init.vim|: >
    omni_sql_no_default_maps
<       - Default: This variable is not defined
	- If this variable is defined, no maps are created for OMNI
	  completion.  See |sql-completion-maps| for further discussion.
>
    omni_sql_use_tbl_alias
<	- Default: a
	- This setting is only used when generating a comma-separated
	  column list.	By default the map is <C-C>l.  When generating
	  a column list, an alias can be prepended to the beginning of each
	  column, for example:	e.emp_id, e.emp_name.  This option has three
	  settings: >
		n - do not use an alias
		d - use the default (calculated) alias
		a - ask to confirm the alias name
<
	  An alias is determined following a few rules:
	       1.  If the table name has an '_', then use it as a separator: >
		   MY_TABLE_NAME --> MTN
		   my_table_name

Title: Building SQL Statements Dynamically and Customizing SQL Completion
Summary
This section details two methods for building column lists in SQL statements using the SQL completion plugin: one column at a time and all columns for a table. It explains how to use `<C-C>t`, `<Right>`, `<C-C>c`, `<C-C>l`, and `<C-C>L` to achieve this. It also covers a special provision for select statements, allowing column completion after typing an alias followed by a period. Finally, the section introduces procedure and view completion using `<C-C>p` and `<C-C>v` respectively. Then the options to customize the SQL completion plugin are introduced, specifically around disabling default OMNI completion maps and controlling alias usage when generating comma-separated column lists.