java - 如何通过jdbc在postgres中获取数组基类型

标签 java arrays postgresql jdbc types

如何通过 Java 获取 Postgres 中数组列的基本类型/维度?

我有一个表,其中包含像 int[][]text[] 这样的数组。

当我从 JDBC 遍历元数据时,我只能得到 java.sql.Array 类型。 即使在 information_schema.columns 中,它也简单地存储为 ARRAY。

如何知道基类型及其维度?

我现在正在研究转储表信息的工具。

最佳答案

对于数组基类型,DatabaseMetaData.getColumns()返回包含列元数据的 ResultSet。返回的列之一是 TYPE_NAME。这似乎包含数组基本类型的名称,前缀为下划线。例如,_int4_textpg_type 中有一些关于类型的额外信息这可能会有帮助。

对于维度,它们似乎不太可能出现在元数据中。来自documentation :

However, the current implementation ignores any supplied array size limits, i.e., the behavior is the same as for arrays of unspecified length.

The current implementation does not enforce the declared number of dimensions either. Arrays of a particular element type are all considered to be of the same type, regardless of size or number of dimensions. So, declaring the array size or number of dimensions in CREATE TABLE is simply documentation; it does not affect run-time behavior.

array_dims 函数将返回数组值的当前维度。但由于表格中的每一行都可能不同,我怀疑这对您有帮助。

更新:这些维度似乎在元数据中可用。参见 @a_horse_with_no_name's answer .

关于java - 如何通过jdbc在postgres中获取数组基类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16619113/

相关文章:

database - PostgreSQL 登录尝试失败

java - while 循环中嵌套 if/else 语句的问题

java - 同时重新加载具有并发读取器的多个缓存

arrays - 如何将字符串数组与字符串变量匹配?

无法修改字符数组

hibernate - JBoss 在开发环境中找不到 PostgreSQL 的 JDBC 驱动程序

java - 调用 InputSplit 的 getClass() 时来自 Hadoop 的 JobSplitWriter/SerializationFactory 的 NullPointerException

java - HashSet<String> .contains()

java - 使用 ArrayList <Integer> 对整数进行排序

sql - 如何更新一组行