Americo
Americo

Reputation: 919

Trim both leading and trailing parts of a string with different characters

My Data Field In A Postgres Table Contains:

{"people":0}

I want to only display the number character zero as a result.

I tried using the trim function from the Postgres manual but that seems to only trim both leading and trailing characters when they are the same.

How could I go about trimming the above data field to simply return:

0

I tried doing

trim(leading '{"people":' from jobs.data)

But that simply results in:

0}

Upvotes: 1

Views: 105

Answers (1)

Houari
Houari

Reputation: 5621

Perhaps this can be done with regexp_replace

 select regexp_replace(regexp_replace('{"people":100}', '(.*):',''), '}','');

Upvotes: 1

Related Questions