0

I have been trying to figure out how to cleanly extract some_value from something that looks like this:

SELECT protobuff_text FROM table_name;
>>
resource_id {
   high_part: 10310138280989442894
   low_part: 12186277462739912197
}
...
}
known_field_name: some_value
mask {
  points {
...

It should be extracted without assuming anything about what happens before or after it besides the newline. This is easy in MySQL... but I have been having a hard time figuring it out in postgres.

Any PostgreSQL experts out there who can help me with this?

P.S. The string that is inserted into the database is created via com.google.protobuf.TextFormat.printToString(Message m).

4

1 回答 1

2

尝试类似:

SELECT regexp_matches(protobuff_text,'resource_id\s*\{\s*high\_part\:\s*([0-9]*)\s*low\_part\:\s*([0-9]*)\s*\}') 
FROM table_name;

此正则表达式将为您获取数值,如示例中所示。

对于known_field_name尝试类似的东西:

SELECT regexp_matches(protobuff_text,'known_field_name\:\s*(\w*)') 
FROM table_name;

详情here

于 2013-06-03T20:07:55.587 回答