Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Extract Substrings From Logs

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Extract Substrings From Logs. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Write a query to perform string manipulation to extract specific substrings from a messy log table.

Use messy_logs and log_sources. Extract the policy number, claim ID, and event code when present, while retaining rows with missing or malformed values.

Output

  1. One row per log event with columns event_id, source_name, policy_number, claim_id, and event_code.
  2. Include unmatched source records and missing extracted values as NULL.
  3. Order by received_at, then event_id.

Schema

messy_logs
ColumnTypeDescription
event_idPKINTUnique log event identifier
source_idINTIdentifier of the system that generated the log
received_atTIMESTAMPTimestamp when the log was received
raw_messageTEXTUnstructured log message
log_sources
ColumnTypeDescription
source_idPKINTUnique source identifier
source_nameVARCHAR(100)Human-readable source name
Tablesmessy_logslog_sources
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results