【问题标题】:MATLAB sqlwrite array datatype into PostgreSQL cellMATLAB sqlwrite 数组数据类型到 PostgreSQL 单元
【发布时间】:2021-10-04 20:28:53
【问题描述】:

我正在使用sqlwrite 尝试将表写入 PostgreSQL 数据库。据我了解,Postgres 支持 Array 类型。

我要插入的表有两列 xy,其中列 x 的条目本身就是 1xN 数组。

T = struct;
T.x = [[1 2 3 4 5 6 8 8 9 10]];
T.y = "test_string";

T = struct2table(T);

sqlwrite(conn, 'my_table', matlabTable);

T看起来像这样

T =

  1x2 table

          x                y      
    _____________    _____________

    [1x10 double]    "test_string"

这是我尝试运行代码时遇到的错误

Error using database.postgre.connection/sqlwrite>checkDataTypes (line 315)
x column value must be a numeric array or cell array of numeric scalars.

Error in database.postgre.connection/sqlwrite (line 155)
data = checkDataTypes(typNames,typeCategories,data);

这是 MATLAB 的 sqlwrite 的限制还是我做错了什么?

谢谢。

【问题讨论】:

    标签: arrays database postgresql matlab


    【解决方案1】:

    这是 Matlab 的sqlwrite 和相关函数的限制。它们仅适用于基本数据类型。这对于 Matlab 的数据库工具箱来说是正常的。

    如果你想让它工作,你可能需要将该值转换为 Postgres 可以转换为数组的 SQL 字符串文字,或者只需将数据库工具箱完全替换为支持数组和其他高级 SQL 类型的东西。这里有一些代码可以帮助您入门:https://github.com/janklab/janklab-core/tree/master/Mcode/classes/%2Bjl/%2Bsql

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 2010-12-16
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      相关资源
      最近更新 更多