【问题标题】:PostgreSQL: execute a stored function (getting an error even though the arguments have been casted)PostgreSQL:执行存储的函数(即使参数已被强制转换也会出错)
【发布时间】:2020-05-13 17:50:31
【问题描述】:

我遇到了一个我找不到解决方案的问题。

我已经成功创建了一个函数。这是函数名称和参数:

CREATE OR REPLACE FUNCTION app_private.create_user(username citext, email text, email_is_verified boolean, name text, avatar_url text, title text DEFAULT NULL::text, color character varying DEFAULT NULL::character varying, user_role smallint DEFAULT 0, password text DEFAULT NULL::text)
RETURNS app_public.users
....
CREATE FUNCTION

我还成功地将执行该功能的权限授予角色。并且还创建了一条评论:

grant execute on function app_private.create_user(username citext, email text, email_is_verified bool, name text, avatar_url text, title text, color varchar(7), user_role smallint, password text) to nine_manager;
GRANT    
comment on function app_private.create_user(username citext, email text, email_is_verified bool, name text, avatar_url text, title text, color varchar(7), user_role smallint, password text) is  
    E'Creates a user account.';
COMMENT

但是,当我尝试通过查询创建测试用户时:

SELECT "app_private.create_user"('JS0'::citext, 'test@gmail.com'::text, true::boolean, 'John Smith'::text, 'SY'::text, 'Manager'::text, '#000000'::varchar(7), 5::SMALLINT, 'test'::text);

我得到一个错误:

错误:函数 app_private.create_user(citext, text, boolean, text, text, text, character varying, smallint, text) 不存在
第 1 行:选择 "app_private.create_user"('SY0'::citext, 'test@gmail....

我尝试更改查询和强制转换,但失败了。差点把我的头发拉出来。

提前谢谢你。

【问题讨论】:

  • SELECT "app_private"."create_user" 或完全删除所有那些可怕的双引号
  • 成功了。谢谢你。我在某处读到为中间有句点的名称添加双引号,哎呀!

标签: sql postgresql function stored-functions postgresql-12


【解决方案1】:

在 select 中调用你的函数之前删除双引号

     Select app_private.create_user(....)
      From table;

【讨论】:

  • 非常感谢!删除引号有效! (我觉得自己像个白痴……)
猜你喜欢
  • 1970-01-01
  • 2021-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多