映射postgresql text [] []类型和Java类型 [英] mapping postgresql text[][] type and Java type
问题描述
我的postgresql表包含text [] []类型的字段。在JDBC代码中,我使用了一个String数组,但是一个例外告诉我,类型之间没有匹配。
如果类型之间没有映射,你能否建议我为字符串数组使用e pgsql类型?
I've a postgresql table contains a field of type text[][]. In JDBC code i've used a String array, but an exception told me that theres no matching between type. If there's no mapping between types, could you suggest me e pgsql type for a strings array?
这是代码:
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.
还要注意 text
和字符变化
( varchar
)在PostgreSQL中是不同的数据类型(当 varchar $ c时大致相同$ c>没有长度修饰符)。首先阅读手册中的字符类型。
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屋!