简体   繁体   English

使用字符串函数在Amazon Redshift中反序列化php对象

[英]Deserialize php object in amazon redshift using string functions

I have a table in redshift in which a column is a PHP serialized object. 我在redshift中有一个表,其中的一列是PHP序列化的对象。 I want to use redshift string functions and de-serialize the column and make another temporary table with the deserialized values. 我想使用redshift字符串函数并反序列化该列,并使用反序列化的值制作另一个临时表。 for example: the initial table would look like 例如:初始表看起来像

| col A | |a:1:{i:145;s:2:"14";} | |a:1:{i:145;s:2:"15";} | |a:1:{i:145;s:2:"16";} |

The expected output temporary table for further processing is: 进一步处理的预期输出临时表为:

| Col A | Col B | | 145 | 14 | | 145 | 15 | | 145 | 16 |

How can I use redshift string functions to deserialize this object? 如何使用redshift字符串函数反序列化此对象?

for your particular case it would work like this: 对于您的特定情况,它将像这样工作:

select 
 split_part(split_part('a:1:{i:145;s:2:"14";}',':',4),';',1)
,trim(split_part(split_part('a:1:{i:145;s:2:"14";}',':',6),';',1),'"');

if there can be other formats of this structure this isn't going to work 如果可以有这种结构的其他格式,那将行不通

我想出的解决方案:

SELECT REGEXP_SUBSTR(SPLIT_PART(VALUE,';',1),'[^:]*$') as fieldName1, trim('"' FROM REGEXP_SUBSTR(SPLIT_PART(VALUE,';',2),'[^:]*$')) as fieldName2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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