映射 PostgreSQL text[][] 类型和 Java 类型 [英] Mapping PostgreSQL text[][] type and Java type

查看:30
本文介绍了映射 PostgreSQL text[][] 类型和 Java 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Postgres 表,其中包含一个 text[][] 类型的列.在 JDBC 代码中,我使用了一个 String 数组,但是一个例外告诉我这两个不匹配.如果这些类型之间没有映射,你能建议一个字符串数组的 Postgres 类型吗?

I have a Postgres table containing a column of type text[][]. In JDBC code I've used a String array, but an exception told me that these two do not match. If there's no mapping between these types, could you suggest a Postgres type for a string arrays?

这是代码:

String list = "'{";
        for(int i=0; i<array.length; i++) {
            list+=prodotti[i]+",";
        }
        list+="}'";

        preparedStm.setString(4, list);

推荐答案

要了解多维 PostgreSQL 数组类型,请考虑以下 引自手册:

To understand multi-dimensional PostgreSQL array types consider the following quote from the manual:

当前的实现没有强制执行声明的数量尺寸.特定元素类型的数组都是被认为是同一类型,无论大小或数量方面.因此,在中声明数组大小或维数CREATE TABLE 只是文档;它不影响运行时行为.

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.

在内部,类型text[]text[][]与PostgreSQL相同.如果该列实际上包含二维文本数组,则必须匹配 Java 中的维度.但它也可以包含 1 维或 3 维数组.PostgreSQL 会允许的.

Internally, the types text[], text[][] are the same to PostgreSQL. If the column actually contains 2-dimensional text arrays, you'll have to match the dimensions in Java. But it could contain 1- or 3-dimensional arrays as well. PostgreSQL would allow it.

还要注意 textcharacter variables (varchar) 在 PostgreSQL 中是不同的数据类型(同时做当 varchar 没有长度修饰符时大致相同).首先阅读手册中的字符类型.

Also note that text and character varying (varchar) are different data types in PostgreSQL (while doing largely the same when varchar has no length modifier). Start by reading about character types in the manual.

这篇关于映射 PostgreSQL text[][] 类型和 Java 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆