Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

327
Views
Extracting each line from a text after a certain character and extract the result to a table using postgres

I have a text looking like this:

>Sequenz: Test 1
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG

>Sequenz 2 1234 Organism: Treponema
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG

>Sequenz 3
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG

There is not necessarily a blank line between the text chunks and it might be a various number of lines of 'MTEITAAMVKELRESTGAGM'. The only thing, which is known for sure is a > before each line.

I want resulting in a table like this:

HEADER 
----------
Sequenz: Test 1 
----------
Sequenz 2 1234 Organism: Treponema
----------
Sequenz 3

I tried:

SELECT regexp_matches(regexp_split_to_table( 'text from above', '\n>'),'([A-Z,a-z,0-9]+\s)');

resulting in

HEADER
----------
Sequenz
----------
Sequenz
----------
Sequenz

and

Select regexp_split_to_table('text from bove', '[\\\n>+(.)\\\n]+')

resulting in

HEADER
----------
----------
Sequenz: Test 1 
----------
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG
----------
----------
Sequenz 2 1234 Organism: Treponema 
----------
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG
----------
----------
Sequenz 3 
----------
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try this:

SELECT split_part(regexp_split_to_table(trim(leading '>' from '>Sequenz: Test 1
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG

>Sequenz 2 1234 Organism: Treponema
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG

>Sequenz 3
MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG'), E'>'),E'\n', 1) AS res

Remove trim() function if you want to keep first empty row.

Demo: http://rextester.com/LQXY98290

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!