这是我桌子的简化版本:
class Alert(Base):
__tablename__ = 'alert'
id = Column(Integer, primary_key=True)
created_on = Column(DateTime(timezone=True))
category = Column(Unicode, nullable=False)
parameters = Column(ARRAY(Unicode), nullable=True)
当尝试将下面的多维数组插入表中时,我得到一个DataError,告诉我我的数组格式不正确。
DataError: (DataError) malformed array literal: "numbers"
LINE 1: ...RRAY[ARRAY['key', 'sXl5SoNh0KY'], ARRAY['nu...
^
DETAIL: Array value must start with "{" or dimension information.
'INSERT INTO alert (created_on, category, parameters)
VALUES (%(created_on)s, %(category)s, %(parameters)s)
RETURNING alert.id' {
'created_on': datetime.datetime(2015, 6, 24, 1, 52, 30, 631330, tzinfo=<UTC>)
'category': u'new_cases',
'parameters':
[[u'key', u'sXl5SoNh0KY'],
['numbers', [u'8129431', u'8669290', u'8754131', u'8871813', u'8927606']],
['status', 'all']]
}
我的印象是Postgres&#39; ARRAY类型是多维的,无论它是如何创建的(http://thread.gmane.org/gmane.comp.python.sqlalchemy.user/31186),为什么会出现这个错误?
答案 0 :(得分:3)
PostgreSQL中的数组可以是多维的,但所有元素必须具有相同数量的维度(http://www.postgresql.org/docs/9.4/interactive/arrays.html),因此您可以写:
var counter = 0; // Initialize to zero
function myFunc() {
if (counter++ > 0) { // Check if second click onwards
alert("option changed");
// Event handling code here
}
}
但不是:
SELECT ARRAY[ARRAY[1,2], ARRAY[3,4]];
=> "{{1,2},{3,4}}"