Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 用于创建外部表的Postgres SQL函数_Function_Greenplum - Fatal编程技术网

Function 用于创建外部表的Postgres SQL函数

Function 用于创建外部表的Postgres SQL函数,function,greenplum,Function,Greenplum,我在greenplum DB中有这个函数,由于某些原因它不能正常工作。 当我运行这个函数时,它应该创建一个外部表,但事实并非如此,这是我第一次用Greenplum编写函数,所以请原谅,如果我认为这是一个愚蠢的错误。有人能帮我吗 ------------------------------------------------------------------------------- -- begin maintenance wrapper -- check and delete functi

我在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
-------------------------------------------------------------------------------

这是有效plpgsql函数与一些自由浮动代码片段的特殊混合。我不知道如何理解这一点。您没有声明您的Postgres版本,也没有声明已安装的扩展,也没有声明是否收到错误消息。请澄清。我有一个edite dmy问题,请检查并让我知道这是否回答了您的问题。PostgreSQL中没有创建外部表。看起来你正在使用,但忘了提及……是的,你是对的!我用的是青梅。。。。但是你知道如何让这个函数工作吗?这样它就可以创建一个外部表,并用平面文件中的数据加载这个表……下次请考虑在你的问题中加入关键信息。添加适当的标记,格式化文本,并添加回函数标题。没有标题的函数是没有意义的。我喜欢恰当的问题。