PostgreSQL Flashcards

1
Q

What steps do you want for cleaning string data?

A

Restrict capitalization in column names
Remove extra divider spaces in column names
make column names uniform

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

INITCAP()

A

SELECT INITCAPT(column)
Output: Hello Friend!
Fixes capitalization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

REPLACE()

A

SELECT REPLACE(column, string_to_replace, replacement)
SELECT REPLACE(streets, ‘Main Street’, ‘St’);
Output: Main St

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

LPAD(input_string, length [, fill_value])

A

SELECT LPAD(‘column, 7, ‘X’);
OUTPUT: XXXX123
Prepending text values to a string. The fourth value has to be a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Like

A

Like is used for pattern matching using wildcards such as % or _
SELECT *
FROM employees
WHERE firstname LIKE ‘Ali%’ or firstname LIKE ‘_li’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

%

A

Matches 0 or more characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

_

A

Matches exactly 1 character
Can use multiple _ to represent more than 1 character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

REGEXP_REPLACE()

A

REGEXP_REPLACE(column, ‘regrex’, replacement, ‘g’)

‘g’ = global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

DIFFERENCE()

A

DIFFERENCE is used to compare the SOUNDEX values of two strings and returns a score between 0 and 4:
DIFFERENCE(vehicle_color, ‘GRAY’) = 4;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

SOUNDEX()

A

SOUNDEX is a phonetic algorithm used to match words or strings that sound similar in English. It converts a word to a code based on its pronunciation.
Example:
SOUNDEX(‘GRAY’) → G600
SOUNDEX(‘GREY’) → G600

How well did you know this?
1
Not at all
2
3
4
5
Perfectly