How to upload cell data to PostgreSQL database table?

3 ビュー (過去 30 日間)
Struggling in MATLAB
Struggling in MATLAB 2022 年 7 月 18 日
コメント済み: Siddharth Bhutiya 2022 年 7 月 22 日
I am trying to upload a MATLAB table to PostgreSQL database. But the columns which contain cell datatypes are not showing up in PostgreSQL table. I have tried to convert the cell data into various other datatypes, none of them worked so far. Do you have any suggestions on how to handle cell data which contain double array? I have attached the MATLAB table for reference. I also have attached my .m file if you want to check.
  1 件のコメント
Siddharth Bhutiya
Siddharth Bhutiya 2022 年 7 月 22 日
I am not well versed in databased but I think the problem is you dont have a predefined data type for the cell array of doubles in PostgreSQL. So you might need to get rid of the cell array and only have numeric data. Here's something you can use as a strating point.
>> data
data =
10×3 table
id run_time average_position
__ ___________ ____________________
1 {[ 3.1000]} {[22.8000 -25.5000]}
2 {[ 0.3000]} {[ -67 4.3900]}
3 {[ 8.5000]} {[ 70.6000 28]}
4 {[10.1000]} {[-47.6000 -8.2000]}
5 {[ 7.9000]} {[22.8000 -25.5000]}
6 {[ NaN]} {[ -67 4.3900]}
7 {[ NaN]} {[ 70.6000 28]}
8 {[ NaN]} {[-47.6000 -8.2000]}
9 {[ NaN]} {[22.8000 -25.5000]}
10 {[ 5.3000]} {[ -67 4.3900]}
>> data.(2) = cell2mat(data.(2));
>> data.(3) = cell2mat(data.(3))
data =
10×3 table
id run_time average_position
__ ________ ________________
1 3.1 22.8 -25.5
2 0.3 -67 4.39
3 8.5 70.6 28
4 10.1 -47.6 -8.2
5 7.9 22.8 -25.5
6 NaN -67 4.39
7 NaN 70.6 28
8 NaN -47.6 -8.2
9 NaN 22.8 -25.5
10 5.3 -67 4.39
I dont know if multi-column doubles would work but you can try to see if that is supported in PostgreSQL, if that does not work then you can split that into two double columns using splitvars.
>> data = splitvars(data)
data =
10×4 table
id run_time average_position_1 average_position_2
__ ________ __________________ __________________
1 3.1 22.8 -25.5
2 0.3 -67 4.39
3 8.5 70.6 28
4 10.1 -47.6 -8.2
5 7.9 22.8 -25.5
6 NaN -67 4.39
7 NaN 70.6 28
8 NaN -47.6 -8.2
9 NaN 22.8 -25.5
10 5.3 -67 4.39

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by