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
How Enteros Enhances Cost Allocation and Optimizes Database Performance in the Gaming Sector
- 30 July 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…
How Enteros Optimizes Big Data Management, Azure Databases, and Cost Estimation for Enhanced Performance in the Healthcare Sector
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
How Enteros Enhances Cost Estimation, Shared Costs Management, and RevOps Efficiency in the Education Sector
- 29 July 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…
How Enteros Optimizes Database Performance and Cloud FinOps for the Real Estate Sector
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…