当我尝试运行其中包含函数的SQL脚本时,系统抛出错误:import os
import csv
fileDir = ('C:\\somedir\\')
fName = input('Write the file name here, without extention: ')
lineNo = int(input('Number of lines pr csv file: '))
fNameF = (fName + '.csv')
filehandler = (fileDir + fNameF)
def split(filehandler, delimiter, row_limit,
output_name_template, output_path, keep_headers):
reader = csv.reader(filehandler, delimiter=delimiter)
current_piece = 1
current_out_path = os.path.join(
output_name_template % current_piece
)
current_out_writer = csv.writer(open(current_out_path, 'w'))
current_limit = row_limit
if keep_headers:
headers = reader.next()
current_out_writer.writerow(headers)
for i, row in enumerate(reader):
if i + 1 > current_limit:
current_piece += 1
current_limit = row_limit * current_piece
current_out_path = os.path.join(
output_name_template % current_piece
)
current_out_writer = csv.writer(open(current_out_path, 'w'))
if keep_headers:
current_out_writer.writerow(headers)
current_out_writer.writerow(row)
split(filehandler,',', lineNo,'fName_%s.csv', fileDir, True)
。
任务是获取一堆sql文件并在DB上执行它们。我使用hibernate和postgres,这是POM的依赖项:
org.postgresql.util.PSQLException: A result was returned when none was expected.
所有文件都在循环中一个接一个地执行。我在开始循环之前开始事务,并在循环结束后提交它。每个文件中的文本都传递到 <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.0.12.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
中,然后我称为Query sqlQuery = session.createSQLQuery(script)
。这是遇到具有功能的脚本时失败的地方。似乎只有更复杂的功能会失败,小的功能会通过
例如,通过:
sqlQuery.executeUpdate()
此操作失败(“模式”表示某种模式,例如“公共”):
DO'
DECLARE property RECORD;
BEGIN
FOR property IN SELECT id, default_value
FROM schema.table WHERE type_id = 3 LOOP
if (property.default_value) IS NULL THEN
UPDATE schema.table SET default_value = ''DEFAULT'' WHERE id = property.id;
END IF ;
END LOOP;
END';
这可能是什么原因?
答案 0 :(得分:1)
在您的SELECT
语句中,SELECT
返回一行(因为没有FROM
和没有WHERE
),其中一行的类型为void。它返回一些东西。
create function is_void(p_text text) returns void
language plpgsql as
'begin
end';
select is_void('one');
如果您不希望退货,可以执行以下操作:
create function is_void(p_text text) returns void
language plpgsql as
'begin
end';
do $$
begin
perform is_void('one');
end
$$;