user3369545
user3369545

Reputation: 421

Redshift SQL to remove text after a space

I am trying to remove the text after space from the below example (the name of the data field is model

R17245 20 should return just R17245

FG789 32 should return just FG789...

Query tried

Select regex_replace(model,'','')

Upvotes: 0

Views: 861

Answers (2)

Avi Kasliwal
Avi Kasliwal

Reputation: 11

You can split your input string on ' ' and then take the first part. Sample code (Redshift) :

SELECT model, SPLIT_PART (model, ' ', 1) as model_processed 
FROM yourTable;

Documentation link : https://docs.aws.amazon.com/redshift/latest/dg/SPLIT_PART.html

Upvotes: 1

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521249

Assuming the logic here is to remove everything from the first space onwards, you may use:

SELECT model, REGEXP_REPLACE(model, ' .*$', '') AS model_out
FROM yourTable;

Upvotes: 1

Related Questions