Appearance
SUBSTR
Return a substring from a character string, based on start and end values. See also SUBSTRING.
SUBSTR(string, start [, count])
Note: SUBSTRING
and SUBSTR
are not synonymous. SUBSTRING
returns a VARCHAR
data type, but SUBSTR
returns the data type of its input string.
- string
- An expression that evaluates to a character string. The data type of this string determines the return type of the function.
- start
- Starting position of the substring (an integer).
- count
- Number of characters in the substring.
The following example returns two substrings of the ftscore
column, which contains 3-character strings such as 1-1
, 2-1
, 0-0
, 3-2
, and so on. The first substring returns only the first character, and the second substring returns only the third character.
premdb=# SELECT ftscore, SUBSTR(ftscore,1,1) homegoals, SUBSTR(ftscore,3,1) awaygoals
FROM match WHERE seasonid=2 AND htid=2 AND atid=52;
ftscore | homegoals | awaygoals
---------+-----------+-----------
1-2 | 1 | 2
(1 row)