0
0
PostgreSQLquery~5 mins

String length and position functions in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the length() function do in PostgreSQL?
The length() function returns the number of characters in a string. For example, length('hello') returns 5.
Click to reveal answer
beginner
How do you find the position of a substring inside a string in PostgreSQL?
Use the position(substring IN string) function. It returns the starting index of the substring or 0 if not found. For example, position('cat' IN 'concatenate') returns 4.
Click to reveal answer
beginner
What will length('') return?
It returns 0 because the string is empty and has no characters.
Click to reveal answer
beginner
If position('x' IN 'example') returns 2, what does that mean?
It means the letter 'x' first appears at the 2nd character position in the string 'example'.
Click to reveal answer
intermediate
What is the difference between length() and char_length() in PostgreSQL?
Both return the number of characters in a string. They are synonyms and behave the same for normal text strings.
Click to reveal answer
What does length('database') return?
A8
B7
C9
D0
What is the result of position('sql' IN 'postgresql')?
A7
B5
C0
D8
If a substring is not found, what does position() return?
A-1
BNULL
C0
D1
Which function can be used to get the number of characters in a string?
Alength()
Bposition()
Csubstring()
Dtrim()
What does length(' ') return for a string with a single space?
A0
B1
C2
DNULL
Explain how to find the position of a substring within a string in PostgreSQL and what the result means.
Think about how you look for a word inside a sentence and find where it starts.
You got /5 concepts.
    Describe how to get the length of a string and what the length represents.
    Imagine counting letters in a word or sentence.
    You got /4 concepts.