我在greenplum DB中有这个功能,由于某种原因它无法正常工作。 当我运行这个函数时,它应该创建一个外部表,但事实并非如此,这是我第一次在Greenplum中编写一个函数,所以请原谅我是否应该是一个愚蠢的错误。任何人都可以尝试帮助我。
-------------------------------------------------------------------------------
-- begin maintenance wrapper
-- check and delete function with different return type
if (
select 1 from pg_proc p
inner join pg_namespace n on p.pronamespace = n.oid
inner join pg_type t on p.prorettype = t.oid
where n.nspname = 'staging'
and p.proname = 'fn_file_data_create_external'
and oidvectortypes(p.proargtypes) = 'text, text'
and t.typname <> 'void'
)
drop function if exists staging.fn_file_data_create_external(text, text);
-- second check
if (
select 1 from pg_proc p
inner join pg_namespace n on p.pronamespace = n.oid
inner join pg_type t on p.prorettype = t.oid
where n.nspname = 'staging'
and p.proname = 'fn_file_data_create_external'
and oidvectortypes(p.proargtypes) = 'text, text'
and t.typname <> 'void'
)
begin
print '<<< Cannot delete last version of staging.fn_file_data_create_external >>>';
end
else
begin
-- end maintenance wrapper
-------------------------------------------------------------------------------
/******************************************************************************
author name : XXXXXXXXXXX
svn location :
table name : staging.fn_file_data_create_external
description : create file_data external table
revision history :
version date modified by issue no description
------- ---------- ---------------- -------- ---------------
1.0 12-26-2013 XXXXXXXXXXXX initial version
******************************************************************************/
CREATE OR REPLACE FUNCTION staging.fn_file_data_create_external( gpfdist_server_ text, file_name_ text)
RETURNS void AS
$BODY$
declare
schema_ constant text := 'staging';
owner_ constant text := 'dev_staging_develop';
table_ text := 'file_data';
source_ text := schema_ ||'.'||'ext_'||table_||'_'||file_name_;
begin
-----------------------------------------------------------------------
raise notice 'Prepare external table';
-----------------------------------------------------------------------
execute 'drop external table if exists '||source_;
execute 'create external table '||source_||' (data_line text)
location('||quote_literal(
'gpfdist://'
||gpfdist_server_
||'/'
||file_name_
||'.dat')
||') format ''TEXT'' encoding ''LATIN1''';
execute 'ALTER EXTERNAL TABLE '||source_||' OWNER TO '||owner_;
end
$BODY$
LANGUAGE plpgsql VOLATILE;
ALTER FUNCTION staging.fn_file_data_create_external(text, text)
OWNER TO dev_staging_develop;
-------------------------------------------------------------------------------
-- begin maintenance wrapper
if (
select 1 from pg_proc p
inner join pg_namespace n on p.pronamespace = n.oid
where n.nspname = 'staging'
and p.proname = 'fn_file_data_create_external'
and oidvectortypes(p.proargtypes) = 'text, text'
)
print '<<< Function staging.fn_file_data_create_external exists, check errors in output >>>';
else
print '<<< Error creation function staging.fn_file_data_create_external exists >>>';
end
-- end maintenance wrapper
-------------------------------------------------------------------------------