Preamble
PostgreSQL substring function allows extracting substring from a string.
Syntax of the substring function in PostgreSQL
substring( string [from start_position] [for length] )
Parameters and function arguments
- string – Source line.
- start_position – Optional. This is the initial position to extract. If this parameter is not specified, the substring function will start from position 1 (which is the first position in the string).
- length – Optional. This is the number of characters to be extracted. If this parameter is not specified, the substring function will return the whole line (from start_position to the end of the string).
Note:
- The first position in the string is 1.
The substring function can be used in the following PostgreSQL versions
PostgreSQL 11, PostgreSQL 10, PostgreSQL 9.6, PostgreSQL 9.5, PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4.
Consider some examples of the substring function to understand how to use the substring function in PostgreSQL.
For example:
SELECT substring('Google.com' for 6);
--Result: Google
SELECT substring('Google.com' from 1 to 6);
--Result: Google
SELECT substring('Google.com' from 2 for 5);
--Result: oogle
SELECT substring('Google.com' from 5 to 8);
--Result: le.com
SELECT substring('Google.com' from 8 to 3);
--Result: com
SELECT substring('Google.com' from 8);
--Result: com
Learn PostgreSQL Tutorial; Full Course for Beginners
About Enteros
Enteros offers a patented database performance management SaaS platform. It proactively identifies root causes of complex business-impacting database scalability and performance issues across a growing number of clouds, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
Optimizing Enterprise Performance in the Telecom Sector: How Enteros Drives Cloud FinOps Excellence
- 17 April 2025
- Database Performance Management
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Accelerating Performance Growth in the Insurance Sector with Enteros: Uniting Database Optimization and RevOps Efficiency
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Harnessing Enteros and Generative AI to Empower Database Administrators in the Hospitality Sector through a Scalable SaaS Platform
- 16 April 2025
- Database Performance Management
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Driving Cost Attribution and Performance Efficiency in the Travel Sector with AIOps and Cloud-Based Database Platforms
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…