In PostgreSQL, we can extract a substring matching a specified POSIX regular expression. Matching Substrings with SQL Regular Expression We now have a rough idea about the name of every book. However, we can extract only the first 15 characters from the name column of the table: SELECT We want to get a rough idea about the name of each book. We have started extraction at position 5, and 2 characters have been extracted. Here is another example: SELECT substring('Guru99' from 5 for 2) Since the number of characters to be extracted was not specified, the extraction ran to the end of the string. Let us extract 99 from the string Guru99: SELECT substring('Guru99' from 5) We specified that the extraction of the substring should begin from position 1, and 4 characters should be extracted. The following example shows how to specify the starting position: SELECT substring('Guru99' from 1 for 4) 4 characters were extracted to return the above. We did not specify the starting position, so the extraction of the substring start at position 1. In this example, we want to extract the first 4 characters from the word Guru99: SELECT substring('Guru99' for 4) If you omit this parameter, the function will extract from starting_position to the end of the string. It denotes the number of characters to be extracted from the string. If you omit this parameter, the extraction will start from position 1, which is the first character in the string. It denotes the place where the extraction of the string will begin. The source string whose data type is varchar, char, string, etc. The PostgreSQL substring function takes the following syntax: substring( string ) Matching Substrings with SQL Regular Expression.In this PostgreSQL tutorial, you will learn: Instead of returning the whole string, it only returns a part of it. The PostgreSQL substring function helps you to extract and return part of a string.
0 Comments
Leave a Reply. |