简体   繁体   中英

How to get everything in a string up to the 2nd or 3rd comma in postgresql?

I already had help here .

But when I tried switching from spaces to commas it didn't work

Basically if I have an address:

FLAT 10, ELGAR HOUSE, CHURCHILL GARDENS, LONDON, SW1V 3BS

I need to cut it and have as output only

FLAT 10, ELGAR HOUSE

How to do it in postgresql?

I guess you could use split_part function to get string before occurrence of 2nd comma

select split_part(address, ',', 1) || ',' || split_part(address, ',', 2)
from your_table

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM