我正在尝试在MySQL Workbench / j中测试我的存储过程。尝试调用存储过程时出现错误。
我创建了一个表来存储存储过程的结果
CREATE TABLE IF NOT EXISTS ableok
(
name VARCHAR(50) ENCODE lzo
);
这是我的存储过程:
CREATE OR REPLACE PROCEDURE sp_GetDistSchema()
AS '
BEGIN
SELECT table_schema INTO ableok FROM information_schema.tables;
END;
'
LANGUAGE plpgsql;
这是我在SQL Workbench / j中调用存储过程的方式:
call sp_getdistschema();
结果:
An error occurred when executing the SQL command:
call sp_getdistschema()
[Amazon](500310) Invalid operation: Column "table_schema" has unsupported type "information_schema.sql_identifier".; [SQL State=0A000, DB Errorcode=500310]
1 statement failed.
答案 0 :(得分:0)
SELECT ... INTO结构用于将查询结果存储到变量中。看来您实际上只是在尝试直接填充distTable。尝试以下方法:
更新:在Redshift / PostgreSQL中处理信息模式时,您显然需要使用CAST转换列数据类型:
CREATE OR REPLACE PROCEDURE sp_GetDistSchema()
BEGIN
INSERT INTO distTable SELECT DISTINCT CAST(table_schema AS VARCHAR) FROM information_schema.tables;
END;