Skip to main content
Ctrl+K

Tantor Special Edition 1C 16.10 documentation

Table of contents:

  • Preface
    • 1.  What Is Tantor SE-1C?
    • 2. A Brief History of PostgreSQL
    • 3. What are the differences between Tantor SE 1C 16 and PostgreSQL 16
    • 4. 1C improvements
    • 5. Conventions
    • 6. Bug Reporting Guidelines
  • Part I. Tutorial
    • Chapter 1. Synopsis
      • 1.1. Synopsis
      • 1.2. Architectural Fundamentals
      • 1.3. Creating a Database
      • 1.4. Accessing a Database
    • Chapter 2. The SQL Language
      • 2.1. Introduction
      • 2.2. Concepts
      • 2.3. Creating a New Table
      • 2.4. Populating a Table With Rows
      • 2.5. Querying a Table
      • 2.6. Joins Between Tables
      • 2.7. Aggregate Functions
      • 2.8. Updates
      • 2.9. Deletions
    • Chapter 3. Advanced Features
      • 3.1. Introduction
      • 3.2. Views
      • 3.3. Foreign Keys
      • 3.4. Transactions
      • 3.5. Window Functions
      • 3.6. Inheritance
      • 3.7. Conclusion
  • Part II. The SQL Language
    • Chapter 4. SQL Syntax
      • 4.1. Lexical Structure
      • 4.2. Value Expressions
      • 4.3. Calling Functions
    • Chapter 5. Data Definition
      • 5.1. Table Basics
      • 5.2. Default Values
      • 5.3. Generated Columns
      • 5.4. Constraints
      • 5.5. System Columns
      • 5.6. Modifying Tables
      • 5.7. Privileges
      • 5.8. Row Security Policies
      • 5.9. Schemas
      • 5.10. Inheritance
      • 5.11. Table Partitioning
      • 5.12. Foreign Data
      • 5.13. Other Database Objects
      • 5.14. Dependency Tracking
    • Chapter 6. Data Manipulation
      • 6.1. Inserting Data
      • 6.2. Updating Data
      • 6.3. Deleting Data
      • 6.4. Returning Data from Modified Rows
    • Chapter 7. Queries
      • 7.1. Overview
      • 7.2. Table Expressions
      • 7.3. Select Lists
      • 7.4. Combining Queries (UNION, INTERSECT, EXCEPT)
      • 7.5. Sorting Rows (ORDER BY)
      • 7.6. LIMIT and OFFSET
      • 7.7. VALUES Lists
      • 7.8. WITH Queries (Common Table Expressions)
    • Chapter 8. Data Types
      • 8.1. Numeric Types
      • 8.2. Monetary Types
      • 8.3. Character Types
      • 8.4. Binary Data Types
      • 8.5. Date/Time Types
      • 8.6. Boolean Type
      • 8.7. Enumerated Types
      • 8.8. Geometric Types
      • 8.9. Network Address Types
      • 8.10. Bit String Types
      • 8.11. Text Search Types
      • 8.12. UUID Type
      • 8.13. XML Type
      • 8.14. JSON Types
      • 8.15. Arrays
      • 8.16. Composite Types
      • 8.17. Range Types
      • 8.18. Domain Types
      • 8.19. Object Identifier Types
      • 8.20. pg_lsn Type
      • 8.21. Pseudo-Types
    • Chapter 9. Functions and Operators
      • 9.1. Logical Operators
      • 9.2. Comparison Functions and Operators
      • 9.3. Mathematical Functions and Operators
      • 9.4. String Functions and Operators
      • 9.5. Binary String Functions and Operators
      • 9.6. Bit String Functions and Operators
      • 9.7. Pattern Matching
      • 9.8. Data Type Formatting Functions
      • 9.9. Date/Time Functions and Operators
      • 9.10. Enum Support Functions
      • 9.11. Geometric Functions and Operators
      • 9.12. Network Address Functions and Operators
      • 9.13. Text Search Functions and Operators
      • 9.14. UUID Functions
      • 9.15. XML Functions
      • 9.16. JSON Functions and Operators
      • 9.17. Sequence Manipulation Functions
      • 9.18. Conditional Expressions
      • 9.19. Array Functions and Operators
      • 9.20. Range/Multirange Functions and Operators
      • 9.21. Aggregate Functions
      • 9.22. Window Functions
      • 9.23. Subquery Expressions
      • 9.24. Row and Array Comparisons
      • 9.25. Set Returning Functions
      • 9.26. System Information Functions and Operators
      • 9.27. System Administration Functions
      • 9.28. Trigger Functions
      • 9.29. Event Trigger Functions
      • 9.30. Statistics Information Functions
    • Chapter 10. Type Conversion
      • 10.1. Overview
      • 10.2. Operators
      • 10.3. Functions
      • 10.4. Value Storage
      • 10.5. UNION, CASE, and Related Constructs
      • 10.6. SELECT Output Columns
    • Chapter 11. Indexes
      • 11.1. Introduction
      • 11.2. Index Types
      • 11.3. Multicolumn Indexes
      • 11.4. Indexes and ORDER BY
      • 11.5. Combining Multiple Indexes
      • 11.6. Unique Indexes
      • 11.7. Indexes on Expressions
      • 11.8. Partial Indexes
      • 11.9. Index-Only Scans and Covering Indexes
      • 11.10. Operator Classes and Operator Families
      • 11.11. Indexes and Collations
      • 11.12. Examining Index Usage
    • Chapter 12. Full Text Search
      • 12.1. Introduction
      • 12.2. Tables and Indexes
      • 12.3. Controlling Text Search
      • 12.4. Additional Features
      • 12.5. Parsers
      • 12.6. Dictionaries
      • 12.7. Configuration Example
      • 12.8. Testing and Debugging Text Search
      • 12.9. Preferred Index Types for Text Search
      • 12.10. psql Support
      • 12.11. Limitations
    • Chapter 13. Concurrency Control
      • 13.1. Introduction
      • 13.2. Transaction Isolation
      • 13.3. Explicit Locking
      • 13.4. Data Consistency Checks at the Application Level
      • 13.5. Serialization Failure Handling
      • 13.6. Caveats
      • 13.7. Locking and Indexes
    • Chapter 14. Performance Tips
      • 14.1. Using EXPLAIN
      • 14.2. Statistics Used by the Planner
      • 14.3. Controlling the Planner with Explicit JOIN Clauses
      • 14.4. Populating a Database
      • 14.5. Non-Durable Settings
    • Chapter 15. Parallel Query
      • 15.1. How Parallel Query Works
      • 15.2. When Can Parallel Query Be Used?
      • 15.3. Parallel Plans
      • 15.4. Parallel Safety
  • Part III. Server Administration
    • Chapter 16. Installation from Binaries
      • 16.1. Downloading and Executing the Installer
      • 16.2. Installer Options
    • Chapter 17. Server Setup and Operation
      • 17.1. The Tantor SE-1C User Account
      • 17.2. Creating a Database Cluster
      • 17.3. Starting the Database Server
      • 17.4. Managing Kernel Resources
      • 17.5. Shutting Down the Server
      • 17.6. Upgrading a Tantor SE-1C Cluster
      • 17.7. Preventing Server Spoofing
      • 17.8. Encryption Options
      • 17.9. Secure TCP/IP Connections with SSL
      • 17.10. Secure TCP/IP Connections with GSSAPI Encryption
      • 17.11. Secure TCP/IP Connections with SSH Tunnels
      • 17.12. Registering Event Log on Windows
    • Chapter 18. Server Configuration
      • 18.1. Setting Parameters
      • 18.2. File Locations
      • 18.3. Connections and Authentication
      • 18.4. Resource Consumption
      • 18.5. Write Ahead Log
      • 18.6. Replication
      • 18.7. Query Planning
      • 18.8. Error Reporting and Logging
      • 18.9. Run-time Statistics
      • 18.10. Automatic Vacuuming
      • 18.11. Client Connection Defaults
      • 18.12. Lock Management
      • 18.13. Version and Platform Compatibility
      • 18.14. Error Handling
      • 18.15. Preset Options
      • 18.16. Customized Options
      • 18.17. Developer Options
      • 18.18. Short Options
    • Chapter 19. Client Authentication
      • 19.1. The pg_hba.conf File
      • 19.2. User Name Maps
      • 19.3. Authentication Methods
      • 19.4. Trust Authentication
      • 19.5. Password Authentication
      • 19.6. GSSAPI Authentication
      • 19.7. SSPI Authentication
      • 19.8. Ident Authentication
      • 19.9. Peer Authentication
      • 19.10. LDAP Authentication
      • 19.11. RADIUS Authentication
      • 19.12. Certificate Authentication
      • 19.13. PAM Authentication
      • 19.14. BSD Authentication
      • 19.15. Authentication Problems
    • Chapter 20. Database Roles
      • 20.1. Database Roles
      • 20.2. Role Attributes
      • 20.3. Role Membership
      • 20.4. Dropping Roles
      • 20.5. Predefined Roles
      • 20.6. Function Security
    • Chapter 21. Managing Databases
      • 21.1. Overview
      • 21.2. Creating a Database
      • 21.3. Template Databases
      • 21.4. Database Configuration
      • 21.5. Destroying a Database
      • 21.6. Tablespaces
    • Chapter 22. Localization
      • 22.1. Locale Support
      • 22.2. Collation Support
      • 22.3. Character Set Support
    • Chapter 23. Routine Database Maintenance Tasks
      • 23.1. Routine Vacuuming
      • 23.2. Routine Reindexing
      • 23.3. Log File Maintenance
    • Chapter 24. Backup and Restore
      • 24.1. SQL Dump
      • 24.2. File System Level Backup
      • 24.3. Continuous Archiving and Point-in-Time Recovery (PITR)
    • Chapter 25. High Availability, Load Balancing, and Replication
      • 25.1. Comparison of Different Solutions
      • 25.2. Log-Shipping Standby Servers
      • 25.3. Failover
      • 25.4. Hot Standby
    • Chapter 26. Monitoring Database Activity
      • 26.1. Standard Unix Tools
      • 26.2. The Cumulative Statistics System
      • 26.3. Viewing Locks
      • 26.4. Progress Reporting
      • 26.5. Dynamic Tracing
    • Chapter 27. Monitoring Disk Usage
      • 27.1. Determining Disk Usage
      • 27.2. Disk Full Failure
    • Chapter 28. Reliability and the Write-Ahead Log
      • 28.1. Reliability
      • 28.2. Data Checksums
      • 28.3. Write-Ahead Logging (WAL)
      • 28.4. Asynchronous Commit
      • 28.5. WAL Configuration
      • 28.6. WAL Internals
    • Chapter 29. Logical Replication
      • 29.1. Publication
      • 29.2. Subscription
      • 29.3. Row Filters
      • 29.4. Column Lists
      • 29.5. Conflicts
      • 29.6. Restrictions
      • 29.7. Architecture
      • 29.8. Monitoring
      • 29.9. Security
      • 29.10. Configuration Settings
      • 29.11. Quick Setup
    • Chapter 30. Just-in-Time Compilation (JIT)
      • 30.1. What Is JIT compilation?
      • 30.2. When to JIT?
      • 30.3. Configuration
      • 30.4. Extensibility
  • Part IV. Client Interfaces
    • Chapter 31. libpq — C Library
      • 31.1. Database Connection Control Functions
      • 31.2. Connection Status Functions
      • 31.3. Command Execution Functions
      • 31.4. Asynchronous Command Processing
      • 31.5. Pipeline Mode
      • 31.6. Retrieving Query Results Row-by-Row
      • 31.7. Canceling Queries in Progress
      • 31.8. The Fast-Path Interface
      • 31.9. Asynchronous Notification
      • 31.10. Functions Associated with the COPY Command
      • 31.11. Control Functions
      • 31.12. Miscellaneous Functions
      • 31.13. Notice Processing
      • 31.14. Event System
      • 31.15. Environment Variables
      • 31.16. The Password File
      • 31.17. The Connection Service File
      • 31.18. LDAP Lookup of Connection Parameters
      • 31.19. SSL Support
      • 31.20. Behavior in Threaded Programs
      • 31.21. Building libpq Programs
      • 31.22. Example Programs
    • Chapter 32. Large Objects
      • 32.1. Introduction
      • 32.2. Implementation Features
      • 32.3. Client Interfaces
      • 32.4. Server-Side Functions
      • 32.5. Example Program
    • Chapter 33. ECPG — Embedded SQL in C
      • 33.1. The Concept
      • 33.2. Managing Database Connections
      • 33.3. Running SQL Commands
      • 33.4. Using Host Variables
      • 33.5. Dynamic SQL
      • 33.6. pgtypes Library
      • 33.7. Using Descriptor Areas
      • 33.8. Error Handling
      • 33.9. Preprocessor Directives
      • 33.10. Processing Embedded SQL Programs
      • 33.11. Library Functions
      • 33.12. Large Objects
      • 33.13. C++ Applications
      • 33.14. Embedded SQL Commands
      • 33.15. Informix Compatibility Mode
      • 33.16. Oracle Compatibility Mode
      • 33.17. Internals
    • Chapter 34. The Information Schema
      • 34.1. The Schema
      • 34.2. Data Types
      • 34.3. information_schema_catalog_name
      • 34.4. administrable_role_​authorizations
      • 34.5. applicable_roles
      • 34.6. attributes
      • 34.7. character_sets
      • 34.8. check_constraint_routine_usage
      • 34.9. check_constraints
      • 34.10. collations
      • 34.11. collation_character_set_​applicability
      • 34.12. column_column_usage
      • 34.13. column_domain_usage
      • 34.14. column_options
      • 34.15. column_privileges
      • 34.16. column_udt_usage
      • 34.17. columns
      • 34.18. constraint_column_usage
      • 34.19. constraint_table_usage
      • 34.20. data_type_privileges
      • 34.21. domain_constraints
      • 34.22. domain_udt_usage
      • 34.23. domains
      • 34.24. element_types
      • 34.25. enabled_roles
      • 34.26. foreign_data_wrapper_options
      • 34.27. foreign_data_wrappers
      • 34.28. foreign_server_options
      • 34.29. foreign_servers
      • 34.30. foreign_table_options
      • 34.31. foreign_tables
      • 34.32. key_column_usage
      • 34.33. parameters
      • 34.34. referential_constraints
      • 34.35. role_column_grants
      • 34.36. role_routine_grants
      • 34.37. role_table_grants
      • 34.38. role_udt_grants
      • 34.39. role_usage_grants
      • 34.40. routine_column_usage
      • 34.41. routine_privileges
      • 34.42. routine_routine_usage
      • 34.43. routine_sequence_usage
      • 34.44. routine_table_usage
      • 34.45. routines
      • 34.46. schemata
      • 34.47. sequences
      • 34.48. sql_features
      • 34.49. sql_implementation_info
      • 34.50. sql_parts
      • 34.51. sql_sizing
      • 34.52. table_constraints
      • 34.53. table_privileges
      • 34.54. tables
      • 34.55. transforms
      • 34.56. triggered_update_columns
      • 34.57. triggers
      • 34.58. udt_privileges
      • 34.59. usage_privileges
      • 34.60. user_defined_types
      • 34.61. user_mapping_options
      • 34.62. user_mappings
      • 34.63. view_column_usage
      • 34.64. view_routine_usage
      • 34.65. view_table_usage
      • 34.66. views
  • Part V. Server Programming
    • Chapter 35. Extending SQL
      • 35.1. How Extensibility Works
      • 35.2. The Tantor SE-1C Type System
      • 35.3. User-Defined Functions
      • 35.4. User-Defined Procedures
      • 35.5. Query Language (SQL) Functions
      • 35.6. Function Overloading
      • 35.7. Function Volatility Categories
      • 35.8. Procedural Language Functions
      • 35.9. Internal Functions
      • 35.10. Function Optimization Information
      • 35.11. User-Defined Aggregates
      • 35.12. User-Defined Types
      • 35.13. User-Defined Operators
      • 35.14. Operator Optimization Information
      • 35.15. Interfacing Extensions to Indexes
      • 35.16. Packaging Related Objects into an Extension
      • 35.17. Extension Building Infrastructure
    • Chapter 36. Triggers
      • 36.1. Overview of Trigger Behavior
      • 36.2. Visibility of Data Changes
      • 36.3. Writing Trigger Functions in C
      • 36.4. A Complete Trigger Example
    • Chapter 37. Event Triggers
      • 37.1. Overview of Event Trigger Behavior
      • 37.2. Event Trigger Firing Matrix
      • 37.3. Writing Event Trigger Functions in C
      • 37.4. A Complete Event Trigger Example
      • 37.5. A Table Rewrite Event Trigger Example
    • Chapter 38. The Rule System
      • 38.1. The Query Tree
      • 38.2. Views and the Rule System
      • 38.3. Materialized Views
      • 38.4. Rules on INSERT, UPDATE, and DELETE
      • 38.5. Rules and Privileges
      • 38.6. Rules and Command Status
      • 38.7. Rules Versus Triggers
    • Chapter 39. Procedural Languages
      • 39.1. Installing Procedural Languages
    • Chapter 40. PL/pgSQL — SQL Procedural Language
      • 40.1. Overview
      • 40.2. Structure of PL/pgSQL
      • 40.3. Declarations
      • 40.4. Expressions
      • 40.5. Basic Statements
      • 40.6. Control Structures
      • 40.7. Cursors
      • 40.8. Transaction Management
      • 40.9. Errors and Messages
      • 40.10. Trigger Functions
      • 40.11. PL/pgSQL under the Hood
      • 40.12. Tips for Developing in PL/pgSQL
      • 40.13. Porting from Oracle PL/SQL
    • Chapter 41. PL/Tcl — Tcl Procedural Language
      • 41.1. Overview
      • 41.2. PL/Tcl Functions and Arguments
      • 41.3. Data Values in PL/Tcl
      • 41.4. Global Data in PL/Tcl
      • 41.5. Database Access from PL/Tcl
      • 41.6. Trigger Functions in PL/Tcl
      • 41.7. Event Trigger Functions in PL/Tcl
      • 41.8. Error Handling in PL/Tcl
      • 41.9. Explicit Subtransactions in PL/Tcl
      • 41.10. Transaction Management
      • 41.11. PL/Tcl Configuration
      • 41.12. Tcl Procedure Names
    • Chapter 42. PL/Perl — Perl Procedural Language
      • 42.1. PL/Perl Functions and Arguments
      • 42.2. Data Values in PL/Perl
      • 42.3. Built-in Functions
      • 42.4. Global Values in PL/Perl
      • 42.5. Trusted and Untrusted PL/Perl
      • 42.6. PL/Perl Triggers
      • 42.7. PL/Perl Event Triggers
      • 42.8. PL/Perl Under the Hood
    • Chapter 43. PL/Python — Python Procedural Language
      • 43.1. PL/Python Functions
      • 43.2. Data Values
      • 43.3. Sharing Data
      • 43.4. Anonymous Code Blocks
      • 43.5. Trigger Functions
      • 43.6. Database Access
      • 43.7. Explicit Subtransactions
      • 43.8. Transaction Management
      • 43.9. Utility Functions
      • 43.10. Python 2 vs. Python 3
      • 43.11. Environment Variables
    • Chapter 44. Server Programming Interface
      • 44.1. Interface Functions
      • 44.2. Interface Support Functions
      • 44.3. Memory Management
      • 44.4. Transaction Management
      • 44.5. Visibility of Data Changes
      • 44.6. Examples
    • Chapter 45. Background Worker Processes
    • Chapter 46. Logical Decoding
      • 46.1. Logical Decoding Examples
      • 46.2. Logical Decoding Concepts
      • 46.3. Streaming Replication Protocol Interface
      • 46.4. Logical Decoding SQL Interface
      • 46.5. System Catalogs Related to Logical Decoding
      • 46.6. Logical Decoding Output Plugins
      • 46.7. Logical Decoding Output Writers
      • 46.8. Synchronous Replication Support for Logical Decoding
      • 46.9. Streaming of Large Transactions for Logical Decoding
      • 46.10. Two-phase Commit Support for Logical Decoding
    • Chapter 47. Replication Progress Tracking
    • Chapter 48. Archive Modules
      • 48.1. Initialization Functions
      • 48.2. Archive Module Callbacks
  • Part VI. Reference
    • SQL Commands
    • PostgreSQL Client Applications
    • PostgreSQL Server Applications
  • Part VII. Internals
    • Chapter 49. Overview of PostgreSQL Internals
      • 49.1. The Path of a Query
      • 49.2. How Connections Are Established
      • 49.3. The Parser Stage
      • 49.4. The Tantor SE-1C Rule System
      • 49.5. Planner/Optimizer
      • 49.6. Executor
    • Chapter 50. System Catalogs
      • 50.1. Overview
      • 50.2. pg_aggregate
      • 50.3. pg_am
      • 50.4. pg_amop
      • 50.5. pg_amproc
      • 50.6. pg_attrdef
      • 50.7. pg_attribute
      • 50.8. pg_authid
      • 50.9. pg_auth_members
      • 50.10. pg_cast
      • 50.11. pg_class
      • 50.12. pg_collation
      • 50.13. pg_constraint
      • 50.14. pg_conversion
      • 50.15. pg_database
      • 50.16. pg_db_role_setting
      • 50.17. pg_default_acl
      • 50.18. pg_depend
      • 50.19. pg_description
      • 50.20. pg_enum
      • 50.21. pg_event_trigger
      • 50.22. pg_extension
      • 50.23. pg_foreign_data_wrapper
      • 50.24. pg_foreign_server
      • 50.25. pg_foreign_table
      • 50.26. pg_index
      • 50.27. pg_inherits
      • 50.28. pg_init_privs
      • 50.29. pg_language
      • 50.30. pg_largeobject
      • 50.31. pg_largeobject_metadata
      • 50.32. pg_namespace
      • 50.33. pg_opclass
      • 50.34. pg_operator
      • 50.35. pg_opfamily
      • 50.36. pg_parameter_acl
      • 50.37. pg_partitioned_table
      • 50.38. pg_policy
      • 50.39. pg_proc
      • 50.40. pg_publication
      • 50.41. pg_publication_namespace
      • 50.42. pg_publication_rel
      • 50.43. pg_range
      • 50.44. pg_replication_origin
      • 50.45. pg_rewrite
      • 50.46. pg_seclabel
      • 50.47. pg_sequence
      • 50.48. pg_shdepend
      • 50.49. pg_shdescription
      • 50.50. pg_shseclabel
      • 50.51. pg_statistic
      • 50.52. pg_statistic_ext
      • 50.53. pg_statistic_ext_data
      • 50.54. pg_subscription
      • 50.55. pg_subscription_rel
      • 50.56. pg_tablespace
      • 50.57. pg_transform
      • 50.58. pg_trigger
      • 50.59. pg_ts_config
      • 50.60. pg_ts_config_map
      • 50.61. pg_ts_dict
      • 50.62. pg_ts_parser
      • 50.63. pg_ts_template
      • 50.64. pg_type
      • 50.65. pg_user_mapping
    • Chapter 51. System Views
      • 51.1. Overview
      • 51.2. pg_available_extensions
      • 51.3. pg_available_extension_versions
      • 51.4. pg_backend_memory_contexts
      • 51.5. pg_config
      • 51.6. pg_cursors
      • 51.7. pg_file_settings
      • 51.8. pg_group
      • 51.9. pg_hba_file_rules
      • 51.10. pg_ident_file_mappings
      • 51.11. pg_indexes
      • 51.12. pg_locks
      • 51.13. pg_matviews
      • 51.14. pg_policies
      • 51.15. pg_prepared_statements
      • 51.16. pg_prepared_xacts
      • 51.17. pg_publication_tables
      • 51.18. pg_replication_origin_status
      • 51.19. pg_replication_slots
      • 51.20. pg_roles
      • 51.21. pg_rules
      • 51.22. pg_seclabels
      • 51.23. pg_sequences
      • 51.24. pg_settings
      • 51.25. pg_shadow
      • 51.26. pg_shmem_allocations
      • 51.27. pg_stats
      • 51.28. pg_stats_ext
      • 51.29. pg_stats_ext_exprs
      • 51.30. pg_tables
      • 51.31. pg_timezone_abbrevs
      • 51.32. pg_timezone_names
      • 51.33. pg_user
      • 51.34. pg_user_mappings
      • 51.35. pg_views
    • Chapter 52. Frontend/Backend Protocol
      • 52.1. Overview
      • 52.2. Message Flow
      • 52.3. SASL Authentication
      • 52.4. Streaming Replication Protocol
      • 52.5. Logical Streaming Replication Protocol
      • 52.6. Message Data Types
      • 52.7. Message Formats
      • 52.8. Error and Notice Message Fields
      • 52.9. Logical Replication Message Formats
      • 52.10. Summary of Changes since Protocol 2.0
    • Chapter 53. PostgreSQL Coding Conventions
      • 53.1. Formatting
      • 53.2. Reporting Errors Within the Server
      • 53.3. Error Message Style Guide
      • 53.4. Miscellaneous Coding Conventions
    • Chapter 54. Native Language Support
      • 54.1. For the Translator
      • 54.2. For the Programmer
    • Chapter 55. Writing a Procedural Language Handler
    • Chapter 56. Writing a Foreign Data Wrapper
      • 56.1. Foreign Data Wrapper Functions
      • 56.2. Foreign Data Wrapper Callback Routines
      • 56.3. Foreign Data Wrapper Helper Functions
      • 56.4. Foreign Data Wrapper Query Planning
      • 56.5. Row Locking in Foreign Data Wrappers
    • Chapter 57. Writing a Table Sampling Method
      • 57.1. Sampling Method Support Functions
    • Chapter 58. Writing a Custom Scan Provider
      • 58.1. Creating Custom Scan Paths
      • 58.2. Creating Custom Scan Plans
      • 58.3. Executing Custom Scans
    • Chapter 59. Genetic Query Optimizer
      • 59.1. Query Handling as a Complex Optimization Problem
      • 59.2. Genetic Algorithms
      • 59.3. Genetic Query Optimization (GEQO) in PostgreSQL
      • 59.4. Further Reading
    • Chapter 60. Table Access Method Interface Definition
    • Chapter 61. Index Access Method Interface Definition
      • 61.1. Basic API Structure for Indexes
      • 61.2. Index Access Method Functions
      • 61.3. Index Scanning
      • 61.4. Index Locking Considerations
      • 61.5. Index Uniqueness Checks
      • 61.6. Index Cost Estimation Functions
    • Chapter 62. Generic WAL Records
    • Chapter 63. Custom WAL Resource Managers
    • Chapter 64. B-Tree Indexes
      • 64.1. Introduction
      • 64.2. Behavior of B-Tree Operator Classes
      • 64.3. B-Tree Support Functions
      • 64.4. Implementation
    • Chapter 65. GiST Indexes
      • 65.1. Introduction
      • 65.2. Built-in Operator Classes
      • 65.3. Extensibility
      • 65.4. Implementation
      • 65.5. Examples
    • Chapter 66. SP-GiST Indexes
      • 66.1. Introduction
      • 66.2. Built-in Operator Classes
      • 66.3. Extensibility
      • 66.4. Implementation
      • 66.5. Examples
    • Chapter 67. GIN Indexes
      • 67.1. Introduction
      • 67.2. Built-in Operator Classes
      • 67.3. Extensibility
      • 67.4. Implementation
      • 67.5. GIN Tips and Tricks
      • 67.6. Limitations
      • 67.7. Examples
    • Chapter 68. BRIN Indexes
      • 68.1. Introduction
      • 68.2. Built-in Operator Classes
      • 68.3. Extensibility
    • Chapter 69. Hash Indexes
      • 69.1. Overview
      • 69.2. Implementation
    • Chapter 70. Database Physical Storage
      • 70.1. Database File Layout
      • 70.2. TOAST
      • 70.3. Free Space Map
      • 70.4. Visibility Map
      • 70.5. The Initialization Fork
      • 70.6. Database Page Layout
      • 70.7. Heap-Only Tuples (HOT)
    • Chapter 71. Transaction Processing
      • 71.1. Transactions and Identifiers
      • 71.2. Transactions and Locking
      • 71.3. Subtransactions
      • 71.4. Two-Phase Transactions
    • Chapter 72. System Catalog Declarations and Initial Contents
      • 72.1. System Catalog Declaration Rules
      • 72.2. System Catalog Initial Data
      • 72.3. BKI File Format
      • 72.4. BKI Commands
      • 72.5. Structure of the Bootstrap BKI File
      • 72.6. BKI Example
    • Chapter 73. How the Planner Uses Statistics
      • 73.1. Row Estimation Examples
      • 73.2. Multivariate Statistics Examples
      • 73.3. Planner Statistics and Security
    • Chapter 74. Backup Manifest Format
      • 74.1. Backup Manifest Top-level Object
      • 74.2. Backup Manifest File Object
      • 74.3. Backup Manifest WAL Range Object
  • Part VIII. Appendixes
    • Appendix A. Tantor SE-1C Error Codes
    • Appendix B. Date/Time Support
      • B.1. Date/Time Input Interpretation
      • B.2. Handling of Invalid or Ambiguous Timestamps
      • B.3. Date/Time Key Words
      • B.4. Date/Time Configuration Files
      • B.5. POSIX Time Zone Specifications
      • B.6. History of Units
      • B.7. Julian Dates
    • Appendix C. SQL Key Words
    • Appendix D. SQL Conformance
      • D.1. Supported Features
      • D.2. Unsupported Features
      • D.3. XML Limits and Conformance to SQL/XML
    • Appendix E. Release Notes
      • E.1. Release Notes for Tantor SE-1C 16.10.2
      • E.2. Release Notes for Tantor SE-1C 16.10.1
      • E.3. Release Notes for Tantor SE-1C 16.8.1
      • E.4. Release Notes for Tantor SE-1C 16.8.0
      • E.5. Release Notes for Tantor SE-1C 16.6.2
      • E.6. Release Notes for Tantor SE-1C 16.6.1
      • E.7. Release Notes for Tantor SE-1C 16.6.0
      • E.8. Release Notes for Tantor SE-1C 16.4.0
      • E.9. Release Notes for Tantor SE-1C 16.2.1
      • E.10. Release 16.10
      • E.11. Release 16.9
      • E.12. Release 16.8
      • E.13. Release 16.7
      • E.14. Release 16.6
      • E.15. Release 16.5
      • E.16. Release 16.4
      • E.17. Release 16.3
      • E.18. Release 16.2
      • E.19. Release 16.1
      • E.20. Release 16
      • E.21. Prior Releases
    • Appendix F. Additional Supplied Modules and Extensions
      • F.1. adminpack — pgAdmin support toolpack
      • F.2. amcheck — tools to verify table and index consistency
      • F.3. auth_delay — pause on authentication failure
      • F.4. auto_explain — log execution plans of slow queries
      • F.5. basebackup_to_shell — example “shell” pg_basebackup module
      • F.6. basic_archive — an example WAL archive module
      • F.7. bloom — bloom filter index access method
      • F.8. btree_gin — GIN operator classes with B-tree behavior
      • F.9. btree_gist — GiST operator classes with B-tree behavior
      • F.10. citext — a case-insensitive character string type
      • F.11. spi — Server Programming Interface features/examples
      • F.12. credcheck
      • F.13. cube — a multi-dimensional cube data type
      • F.14. dbcopies_decoding
      • F.15. dblink — connect to other PostgreSQL databases
      • F.16. dict_int — example full-text search dictionary for integers
      • F.17. dict_xsyn — example synonym full-text search dictionary
      • F.18. earthdistance — calculate great-circle distances
      • F.19. fasttrun
      • F.20. file_fdw — access data files in the server’s file system
      • F.21. fulleq
      • F.22. fuzzystrmatch — determine string similarities and distance
      • F.23. hstore — hstore key/value datatype
      • F.24. HypoPG
      • F.25. intagg — integer aggregator and enumerator
      • F.26. intarray — manipulate arrays of integers
      • F.27. isn — data types for international standard numbers (ISBN, EAN, UPC, etc.)
      • F.28. lo — manage large objects
      • F.29. ltree — hierarchical tree-like data type
      • F.30. mchar
      • F.31. old_snapshot — inspect old_snapshot_threshold state
      • F.32. online_analyze
      • F.33. pageinspect — low-level inspection of database pages
      • F.34. page_repair
      • F.35. passwordcheck — verify password strength
      • F.36. pgAudit
      • F.37. pgAudit Log to File
      • F.38. pg_buffercache — inspect Tantor SE-1C buffer cache state
      • F.39. pg_cron
      • F.40. pgcrypto — cryptographic functions
      • F.41. pg_freespacemap — examine the free space map
      • F.42. pg_hint_plan
      • F.43. pg_prewarm — preload relation data into buffer caches
      • F.44. pg_repack
      • F.45. pgrowlocks — show a table’s row locking information
      • F.46. pg_stat_kcache
      • F.47. pg_stat_statements — track statistics of SQL planning and execution
      • F.48. pgstattuple — obtain tuple-level statistics
      • F.49. pg_store_plans
      • F.50. pg_surgery — perform low-level surgery on relation data
      • F.51. pg_trace
      • F.52. pg_trgm — support for similarity of text using trigram matching
      • F.53. pg_uuidv7
      • F.54. pg_visibility — visibility map information and utilities
      • F.55. pg_wait_sampling
      • F.56. pg_walinspect — low-level WAL inspection
      • F.57. plantuner
      • F.58. postgres_fdw — access data stored in external Tantor SE-1C servers
      • F.59. seg — a datatype for line segments or floating point intervals
      • F.60. sepgsql — SELinux-, label-based mandatory access control (MAC) security module
      • F.61. sslinfo — obtain client SSL information
      • F.62. tablefunc — functions that return tables (crosstab and others)
      • F.63. tcn — a trigger function to notify listeners of changes to table content
      • F.64. test_decoding — SQL-based test/example module for WAL logical decoding
      • F.65. transp_anon
      • F.66. tsm_system_rows — the SYSTEM_ROWS sampling method for TABLESAMPLE
      • F.67. tsm_system_time — the SYSTEM_TIME sampling method for TABLESAMPLE
      • F.68. unaccent — a text search dictionary which removes diacritics
      • F.69. uuid-ossp — a UUID generator
      • F.70. wal2json
      • F.71. xml2 — XPath querying and XSLT functionality
    • Appendix G. Additional Supplied Programs
      • G.1. Client Applications
      • G.2. Server Applications
    • Appendix H. Additional External Modules
      • H.1. ldap2pg
      • H.2. MySQL Foreign Data Wrapper
      • H.3. Oracle FDW
      • H.4. pg_cluster
      • H.5. pg_configurator
      • H.6. pg_timetable
      • H.7. pgbouncer
      • H.8. TDS Foreign data wrapper
    • Appendix I. External Projects
      • I.1. Client Interfaces
      • I.2. Administration Tools
      • I.3. Procedural Languages
      • I.4. Extensions
    • Appendix J. Tantor SE-1C Limits
    • Appendix K. Acronyms
    • Appendix L. Glossary
    • Appendix M. Color Support
      • M.1. When Color is Used
      • M.2. Configuring the Colors
    • Appendix N. Obsolete or Renamed Features
      • N.1. recovery.conf file merged into postgresql.conf
      • N.2. Default Roles Renamed to Predefined Roles
      • N.3. pg_xlogdump renamed to pg_waldump
      • N.4. pg_resetxlog renamed to pg_resetwal
      • N.5. pg_receivexlog renamed to pg_receivewal
  • Bibliography
  • Index

12.3. Controlling Text Search

12.3. Controlling Text Search#

12.3. Controlling Text Search
12.3. Controlling Text Search
Prev UpChapter 12. Full Text SearchHome Next

12.3. Controlling Text Search #

12.3.1. Parsing Documents
12.3.2. Parsing Queries
12.3.3. Ranking Search Results
12.3.4. Highlighting Results

To implement full text searching there must be a function to create a tsvector from a document and a tsquery from a user query. Also, we need to return results in a useful order, so we need a function that compares documents with respect to their relevance to the query. It's also important to be able to display the results nicely. Tantor SE-1C provides support for all of these functions.

12.3.1. Parsing Documents #

Tantor SE-1C provides the function to_tsvector for converting a document to the tsvector data type.

to_tsvector([ config regconfig, ] document text) returns tsvector

to_tsvector parses a textual document into tokens, reduces the tokens to lexemes, and returns a tsvector which lists the lexemes together with their positions in the document. The document is processed according to the specified or default text search configuration. Here is a simple example:

SELECT to_tsvector('english', 'a fat  cat sat on a mat - it ate a fat rats');
                  to_tsvector
-----------------------------------------------------
 'ate':9 'cat':3 'fat':2,11 'mat':7 'rat':12 'sat':4

In the example above we see that the resulting tsvector does not contain the words a, on, or it, the word rats became rat, and the punctuation sign - was ignored.

The to_tsvector function internally calls a parser which breaks the document text into tokens and assigns a type to each token. For each token, a list of dictionaries (Section 12.6) is consulted, where the list can vary depending on the token type. The first dictionary that recognizes the token emits one or more normalized lexemes to represent the token. For example, rats became rat because one of the dictionaries recognized that the word rats is a plural form of rat. Some words are recognized as stop words (Section 12.6.1), which causes them to be ignored since they occur too frequently to be useful in searching. In our example these are a, on, and it. If no dictionary in the list recognizes the token then it is also ignored. In this example that happened to the punctuation sign - because there are in fact no dictionaries assigned for its token type (Space symbols), meaning space tokens will never be indexed. The choices of parser, dictionaries and which types of tokens to index are determined by the selected text search configuration (Section 12.7). It is possible to have many different configurations in the same database, and predefined configurations are available for various languages. In our example we used the default configuration english for the English language.

The function setweight can be used to label the entries of a tsvector with a given weight, where a weight is one of the letters A, B, C, or D. This is typically used to mark entries coming from different parts of a document, such as title versus body. Later, this information can be used for ranking of search results.

Because to_tsvector(NULL) will return NULL, it is recommended to use coalesce whenever a field might be null. Here is the recommended method for creating a tsvector from a structured document:

UPDATE tt SET ti =
    setweight(to_tsvector(coalesce(title,'')), 'A')    ||
    setweight(to_tsvector(coalesce(keyword,'')), 'B')  ||
    setweight(to_tsvector(coalesce(abstract,'')), 'C') ||
    setweight(to_tsvector(coalesce(body,'')), 'D');

Here we have used setweight to label the source of each lexeme in the finished tsvector, and then merged the labeled tsvector values using the tsvector concatenation operator ||. (Section 12.4.1 gives details about these operations.)

12.3.2. Parsing Queries #

Tantor SE-1C provides the functions to_tsquery, plainto_tsquery, phraseto_tsquery and websearch_to_tsquery for converting a query to the tsquery data type. to_tsquery offers access to more features than either plainto_tsquery or phraseto_tsquery, but it is less forgiving about its input. websearch_to_tsquery is a simplified version of to_tsquery with an alternative syntax, similar to the one used by web search engines.

to_tsquery([ config regconfig, ] querytext text) returns tsquery

to_tsquery creates a tsquery value from querytext, which must consist of single tokens separated by the tsquery operators & (AND), | (OR), ! (NOT), and <-> (FOLLOWED BY), possibly grouped using parentheses. In other words, the input to to_tsquery must already follow the general rules for tsquery input, as described in Section 8.11.2. The difference is that while basic tsquery input takes the tokens at face value, to_tsquery normalizes each token into a lexeme using the specified or default configuration, and discards any tokens that are stop words according to the configuration. For example:

SELECT to_tsquery('english', 'The & Fat & Rats');
  to_tsquery
---------------
 'fat' & 'rat'

As in basic tsquery input, weight(s) can be attached to each lexeme to restrict it to match only tsvector lexemes of those weight(s). For example:

SELECT to_tsquery('english', 'Fat | Rats:AB');
    to_tsquery
------------------
 'fat' | 'rat':AB

Also, * can be attached to a lexeme to specify prefix matching:

SELECT to_tsquery('supern:*A & star:A*B');
        to_tsquery
--------------------------
 'supern':*A & 'star':*AB

Such a lexeme will match any word in a tsvector that begins with the given string.

to_tsquery can also accept single-quoted phrases. This is primarily useful when the configuration includes a thesaurus dictionary that may trigger on such phrases. In the example below, a thesaurus contains the rule supernovae stars : sn:

SELECT to_tsquery('''supernovae stars'' & !crab');
  to_tsquery
---------------
 'sn' & !'crab'

Without quotes, to_tsquery will generate a syntax error for tokens that are not separated by an AND, OR, or FOLLOWED BY operator.

plainto_tsquery([ config regconfig, ] querytext text) returns tsquery

plainto_tsquery transforms the unformatted text querytext to a tsquery value. The text is parsed and normalized much as for to_tsvector, then the & (AND) tsquery operator is inserted between surviving words.

Example:

SELECT plainto_tsquery('english', 'The Fat Rats');
 plainto_tsquery
-----------------
 'fat' & 'rat'

Note that plainto_tsquery will not recognize tsquery operators, weight labels, or prefix-match labels in its input:

SELECT plainto_tsquery('english', 'The Fat & Rats:C');
   plainto_tsquery
---------------------
 'fat' & 'rat' & 'c'

Here, all the input punctuation was discarded.

phraseto_tsquery([ config regconfig, ] querytext text) returns tsquery

phraseto_tsquery behaves much like plainto_tsquery, except that it inserts the <-> (FOLLOWED BY) operator between surviving words instead of the & (AND) operator. Also, stop words are not simply discarded, but are accounted for by inserting <N> operators rather than <-> operators. This function is useful when searching for exact lexeme sequences, since the FOLLOWED BY operators check lexeme order not just the presence of all the lexemes.

Example:

SELECT phraseto_tsquery('english', 'The Fat Rats');
 phraseto_tsquery
------------------
 'fat' <-> 'rat'

Like plainto_tsquery, the phraseto_tsquery function will not recognize tsquery operators, weight labels, or prefix-match labels in its input:

SELECT phraseto_tsquery('english', 'The Fat & Rats:C');
      phraseto_tsquery
-----------------------------
 'fat' <-> 'rat' <-> 'c'

websearch_to_tsquery([ config regconfig, ] querytext text) returns tsquery

websearch_to_tsquery creates a tsquery value from querytext using an alternative syntax in which simple unformatted text is a valid query. Unlike plainto_tsquery and phraseto_tsquery, it also recognizes certain operators. Moreover, this function will never raise syntax errors, which makes it possible to use raw user-supplied input for search. The following syntax is supported:

  • unquoted text: text not inside quote marks will be converted to terms separated by & operators, as if processed by plainto_tsquery.

  • "quoted text": text inside quote marks will be converted to terms separated by <-> operators, as if processed by phraseto_tsquery.

  • OR: the word “or” will be converted to the | operator.

  • -: a dash will be converted to the ! operator.

Other punctuation is ignored. So like plainto_tsquery and phraseto_tsquery, the websearch_to_tsquery function will not recognize tsquery operators, weight labels, or prefix-match labels in its input.

Examples:

SELECT websearch_to_tsquery('english', 'The fat rats');
 websearch_to_tsquery
----------------------
 'fat' & 'rat'
(1 row)

SELECT websearch_to_tsquery('english', '"supernovae stars" -crab');
       websearch_to_tsquery
----------------------------------
 'supernova' <-> 'star' & !'crab'
(1 row)

SELECT websearch_to_tsquery('english', '"sad cat" or "fat rat"');
       websearch_to_tsquery
-----------------------------------
 'sad' <-> 'cat' | 'fat' <-> 'rat'
(1 row)

SELECT websearch_to_tsquery('english', 'signal -"segmentation fault"');
         websearch_to_tsquery
---------------------------------------
 'signal' & !( 'segment' <-> 'fault' )
(1 row)

SELECT websearch_to_tsquery('english', '""" )( dummy \\ query <->');
 websearch_to_tsquery
----------------------
 'dummi' & 'queri'
(1 row)

12.3.3. Ranking Search Results #

Ranking attempts to measure how relevant documents are to a particular query, so that when there are many matches the most relevant ones can be shown first. Tantor SE-1C provides two predefined ranking functions, which take into account lexical, proximity, and structural information; that is, they consider how often the query terms appear in the document, how close together the terms are in the document, and how important is the part of the document where they occur. However, the concept of relevancy is vague and very application-specific. Different applications might require additional information for ranking, e.g., document modification time. The built-in ranking functions are only examples. You can write your own ranking functions and/or combine their results with additional factors to fit your specific needs.

The two ranking functions currently available are:

ts_rank([ weights float4[], ] vector tsvector, query tsquery [, normalization integer ]) returns float4

Ranks vectors based on the frequency of their matching lexemes.

ts_rank_cd([ weights float4[], ] vector tsvector, query tsquery [, normalization integer ]) returns float4

This function computes the cover density ranking for the given document vector and query, as described in Clarke, Cormack, and Tudhope's "Relevance Ranking for One to Three Term Queries" in the journal "Information Processing and Management", 1999. Cover density is similar to ts_rank ranking except that the proximity of matching lexemes to each other is taken into consideration.

This function requires lexeme positional information to perform its calculation. Therefore, it ignores any “stripped” lexemes in the tsvector. If there are no unstripped lexemes in the input, the result will be zero. (See Section 12.4.1 for more information about the strip function and positional information in tsvectors.)

For both these functions, the optional weights argument offers the ability to weigh word instances more or less heavily depending on how they are labeled. The weight arrays specify how heavily to weigh each category of word, in the order:

{D-weight, C-weight, B-weight, A-weight}

If no weights are provided, then these defaults are used:

{0.1, 0.2, 0.4, 1.0}

Typically weights are used to mark words from special areas of the document, like the title or an initial abstract, so they can be treated with more or less importance than words in the document body.

Since a longer document has a greater chance of containing a query term it is reasonable to take into account document size, e.g., a hundred-word document with five instances of a search word is probably more relevant than a thousand-word document with five instances. Both ranking functions take an integer normalization option that specifies whether and how a document's length should impact its rank. The integer option controls several behaviors, so it is a bit mask: you can specify one or more behaviors using | (for example, 2|4).

  • 0 (the default) ignores the document length

  • 1 divides the rank by 1 + the logarithm of the document length

  • 2 divides the rank by the document length

  • 4 divides the rank by the mean harmonic distance between extents (this is implemented only by ts_rank_cd)

  • 8 divides the rank by the number of unique words in document

  • 16 divides the rank by 1 + the logarithm of the number of unique words in document

  • 32 divides the rank by itself + 1

If more than one flag bit is specified, the transformations are applied in the order listed.

It is important to note that the ranking functions do not use any global information, so it is impossible to produce a fair normalization to 1% or 100% as sometimes desired. Normalization option 32 (rank/(rank+1)) can be applied to scale all ranks into the range zero to one, but of course this is just a cosmetic change; it will not affect the ordering of the search results.

Here is an example that selects only the ten highest-ranked matches:

SELECT title, ts_rank_cd(textsearch, query) AS rank
FROM apod, to_tsquery('neutrino|(dark & matter)') query
WHERE query @@ textsearch
ORDER BY rank DESC
LIMIT 10;
                     title                     |   rank
-----------------------------------------------+----------
 Neutrinos in the Sun                          |      3.1
 The Sudbury Neutrino Detector                 |      2.4
 A MACHO View of Galactic Dark Matter          |  2.01317
 Hot Gas and Dark Matter                       |  1.91171
 The Virgo Cluster: Hot Plasma and Dark Matter |  1.90953
 Rafting for Solar Neutrinos                   |      1.9
 NGC 4650A: Strange Galaxy and Dark Matter     |  1.85774
 Hot Gas and Dark Matter                       |   1.6123
 Ice Fishing for Cosmic Neutrinos              |      1.6
 Weak Lensing Distorts the Universe            | 0.818218

This is the same example using normalized ranking:

SELECT title, ts_rank_cd(textsearch, query, 32 /* rank/(rank+1) */ ) AS rank
FROM apod, to_tsquery('neutrino|(dark & matter)') query
WHERE  query @@ textsearch
ORDER BY rank DESC
LIMIT 10;
                     title                     |        rank
-----------------------------------------------+-------------------
 Neutrinos in the Sun                          | 0.756097569485493
 The Sudbury Neutrino Detector                 | 0.705882361190954
 A MACHO View of Galactic Dark Matter          | 0.668123210574724
 Hot Gas and Dark Matter                       |  0.65655958650282
 The Virgo Cluster: Hot Plasma and Dark Matter | 0.656301290640973
 Rafting for Solar Neutrinos                   | 0.655172410958162
 NGC 4650A: Strange Galaxy and Dark Matter     | 0.650072921219637
 Hot Gas and Dark Matter                       | 0.617195790024749
 Ice Fishing for Cosmic Neutrinos              | 0.615384618911517
 Weak Lensing Distorts the Universe            | 0.450010798361481

Ranking can be expensive since it requires consulting the tsvector of each matching document, which can be I/O bound and therefore slow. Unfortunately, it is almost impossible to avoid since practical queries often result in large numbers of matches.

12.3.4. Highlighting Results #

To present search results it is ideal to show a part of each document and how it is related to the query. Usually, search engines show fragments of the document with marked search terms. Tantor SE-1C provides a function ts_headline that implements this functionality.

ts_headline([ config regconfig, ] document text, query tsquery [, options text ]) returns text

ts_headline accepts a document along with a query, and returns an excerpt from the document in which terms from the query are highlighted. Specifically, the function will use the query to select relevant text fragments, and then highlight all words that appear in the query, even if those word positions do not match the query's restrictions. The configuration to be used to parse the document can be specified by config; if config is omitted, the default_text_search_config configuration is used.

If an options string is specified it must consist of a comma-separated list of one or more option=value pairs. The available options are:

  • MaxWords, MinWords (integers): these numbers determine the longest and shortest headlines to output. The default values are 35 and 15.

  • ShortWord (integer): words of this length or less will be dropped at the start and end of a headline, unless they are query terms. The default value of three eliminates common English articles.

  • HighlightAll (boolean): if true the whole document will be used as the headline, ignoring the preceding three parameters. The default is false.

  • MaxFragments (integer): maximum number of text fragments to display. The default value of zero selects a non-fragment-based headline generation method. A value greater than zero selects fragment-based headline generation (see below).

  • StartSel, StopSel (strings): the strings with which to delimit query words appearing in the document, to distinguish them from other excerpted words. The default values are “<b>” and “</b>”, which can be suitable for HTML output (but see the warning below).

  • FragmentDelimiter (string): When more than one fragment is displayed, the fragments will be separated by this string. The default is “ ... ”.

Warning: Cross-site scripting (XSS) safety

The output from ts_headline is not guaranteed to be safe for direct inclusion in web pages. When HighlightAll is false (the default), some simple XML tags are removed from the document, but this is not guaranteed to remove all HTML markup. Therefore, this does not provide an effective defense against attacks such as cross-site scripting (XSS) attacks, when working with untrusted input. To guard against such attacks, all HTML markup should be removed from the input document, or an HTML sanitizer should be used on the output.

These option names are recognized case-insensitively. You must double-quote string values if they contain spaces or commas.

In non-fragment-based headline generation, ts_headline locates matches for the given query and chooses a single one to display, preferring matches that have more query words within the allowed headline length. In fragment-based headline generation, ts_headline locates the query matches and splits each match into “fragments” of no more than MaxWords words each, preferring fragments with more query words, and when possible “stretching” fragments to include surrounding words. The fragment-based mode is thus more useful when the query matches span large sections of the document, or when it's desirable to display multiple matches. In either mode, if no query matches can be identified, then a single fragment of the first MinWords words in the document will be displayed.

For example:

SELECT ts_headline('english',
  'The most common type of search
is to find all documents containing given query terms
and return them in order of their similarity to the
query.',
  to_tsquery('english', 'query & similarity'));
                        ts_headline
------------------------------------------------------------
 containing given <b>query</b> terms                       +
 and return them in order of their <b>similarity</b> to the+
 <b>query</b>.

SELECT ts_headline('english',
  'Search terms may occur
many times in a document,
requiring ranking of the search matches to decide which
occurrences to display in the result.',
  to_tsquery('english', 'search & term'),
  'MaxFragments=10, MaxWords=7, MinWords=3, StartSel=<<, StopSel=>>');
                        ts_headline
------------------------------------------------------------
 <<Search>> <<terms>> may occur                            +
 many times ... ranking of the <<search>> matches to decide

ts_headline uses the original document, not a tsvector summary, so it can be slow and should be used with care.


Prev Up Next
12.2. Tables and Indexes Home 12.4. Additional Features

previous

12.2. Tables and Indexes

next

12.4. Additional Features

By Tantor Labs

© Copyright 2025, Tantor Labs.

Commercial use is possible only with written permission from the company LLC “Tantor Labs”
© LLC "Tantor Labs"
  • Technical Support Policy
  • Cookie Processing Policy
  • Website User Agreement
Products
  • Tantor DBMS
  • Tantor Platform
  • Documentation
Contacts
  • +7 495 369-48-16
  • info@tantorlabs.ru
16.10.2 - de035b67 - 2025-11-01 09:05:05