insert_and_replace_syntax.rst 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .. _insert_and_replace_syntax:
  2. INSERT and REPLACE syntax
  3. -------------------------
  4. .. code-block:: none
  5. {INSERT | REPLACE} INTO index [(column, ...)]
  6. VALUES (value, ...)
  7. [, (...)]
  8. INSERT statement is only supported for RT and percolate indexes. It inserts new rows
  9. (documents) into an existing index, with the provided column values.
  10. ``index`` is the name of RT or percolate index into which the new row(s) should be
  11. inserted. The optional column names list lets you only explicitly
  12. specify values for some of the columns present in the index. All the
  13. other columns will be filled with their default values (0 for scalar
  14. types, empty string for text types).
  15. Expressions are not currently supported in INSERT and values should be
  16. explicitly specified.
  17. RT index INSERT features
  18. ~~~~~~~~~~~~~~~~~~~~~~~~
  19. The ID column can be ommited in INSERT statements as RT index supports
  20. of **autoincrement** functionality. Rows with duplicate IDs will
  21. **not** be overwritten by INSERT; use REPLACE to do that. REPLACE
  22. works exactly like INSERT, except that if an old row has the same ID as
  23. a new row, the old row is deleted before the new row is inserted.
  24. Multiple rows can be inserted using a single INSERT statement by
  25. providing several comma-separated, parentheses-enclosed lists of rows
  26. values.
  27. Percolate index INSERT features
  28. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. For percolate indexes INSERT is used to store queries (aka PQ rules) and their meta (id, tags), so the schema is predefined and may include only the following
  30. columns:
  31. * ``id`` - numeric id of stored query (if omited, will be assigned automatically)
  32. * ``query`` - full-text query to store
  33. * ``filters`` - filters to store (without ``query`` will define the full query as full-scan)
  34. * ``tags`` - string with one or many comma-separated tags, which may be used to selectively show/delete saved queries.
  35. All other names for columns are not supported and will trigger an error.
  36. .. code-block:: sql
  37. INSERT INTO pq (id, query, filters) VALUES ( 1, 'filter test', 'gid >= 10' )
  38. INSERT INTO index_name (query) VALUES ( 'full text query terms' );
  39. INSERT INTO index_name (query, tags, filters) VALUES ( 'full text query terms', 'tags', 'filters' );
  40. In case of omitted schema ``INSERT`` expects one or two params, first is full-text ``query``, and second (optional)
  41. is ``tags``. ``id`` in this case will be generated automatically (maximum current id in the index + 1), ``filters`` will be empty.
  42. .. code-block:: sql
  43. INSERT INTO index_name VALUES ( 'full text query terms', 'tags');
  44. INSERT INTO index_name VALUES ( 'full text query terms');
  45. Multiple rows can be inserted using a single INSERT statement by
  46. providing several comma-separated, parentheses-enclosed lists of rows
  47. values.
  48. Also, you can insert values only into local percolate index. Distributed percolate (i.e. distributed index built from percolate agents/locals) is not
  49. supported for INSERTs yet.