plpgsql 相关问题

PL / pgSQL是PostgreSQL的默认过程语言。关于PL / pgSQL的问题也应该被标记为“PostgreSQL”。

postgres插入文本列仅接受数字字符可转换为bigint

CREATE TABLE IF NOT EXISTS public.registered_device ( device_id serial primary key, registration_token text NOT NULL, account_id bigint, last_registered timestamp without time zone NOT NULL DEFAULT timezone('Europe/Tallinn'::text, CURRENT_TIMESTAMP), platform text COLLATE pg_catalog."default", device text COLLATE pg_catalog."default", operating_system text COLLATE pg_catalog."default", application_version_number text COLLATE pg_catalog."default", application_build_number text COLLATE pg_catalog."default", is_muted boolean NOT NULL DEFAULT false, CONSTRAINT registered_device_account_id_fkey FOREIGN KEY (account_id) REFERENCES public.users (uid) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ); -- owner and grants omitted to save space CREATE OR REPLACE FUNCTION public.register_device( arg_registration_token text, arg_account_id bigint, arg_last_registered timestamp without time zone, arg_platform text, arg_device text, arg_operating_system text, arg_application_version_number text, arg_application_build_number text) RETURNS text LANGUAGE 'plpgsql' COST 100 VOLATILE PARALLEL UNSAFE AS $BODY$ DECLARE var_registration_token BIGINT; BEGIN UPDATE public.pilates_registered_device SET account_id = arg_account_id, last_registered = arg_last_registered, platform = arg_platform, device = arg_device, operating_system = arg_operating_system, application_version_number = arg_application_version_number, application_build_number = arg_application_build_number WHERE registration_token = arg_registration_token RETURNING registration_token INTO var_registration_token; IF var_registration_token IS NULL THEN INSERT INTO public.registered_device( registration_token, account_id, last_registered, platform, device, operating_system, application_version_number, application_build_number ) VALUES ( arg_registration_token, arg_account_id, arg_last_registered, arg_platform, arg_device, arg_operating_system, arg_application_version_number, arg_application_build_number ) RETURNING registration_token INTO var_registration_token; END IF; return var_registration_token; END; $BODY$; select public.register_device('xx', 1, localtimestamp, '','','','',''); -- produce ERROR: invalid input syntax for type bigint: "xx" CONTEXT: PL/pgSQL function register_device(text,bigint,timestamp without time zone,text,text,text,text,text) line 17 at SQL statement SQL state: 22P02 select public.register_device('22', 1, localtimestamp, '','','','',''); -- runs w/o errors

回答 1 投票 0



回答 2 投票 0

我如何将表参数传递给此功能? 我的功能像这样: 创建功能所有内容(Waypoints Waypoint) 返回表(node int,xy文本阵列)作为$$ 开始 创建视图结果为... 返回查询(选择 *...

create function everything(waypoints waypoint) returns table(node int, xy text array) as $$ BEGIN create view results as ... return query (select * from results); END; $$ LANGUAGE plpgsql;

回答 1 投票 0

我有一个基于项目目录的新架构的脚本

for %%a in (.) do set this=%%~na -- other stuff here psql -U postgres -d SLSM -e -v v1=%this% -f "NewSchemaSafe.sql"

回答 2 投票 0

回答 1 投票 0

将变量放在函数上,铸造?

在一个地方我有 创建函数updateGeo2(text,float4,float4)返回float作为$$ 后来 选择UpdateGeo2('区域',40.88,-90.56); 我明白了 错误:错误:function updateGeo2(

回答 2 投票 0

postgresql将变量发送到函数,铸造?

在一个地方我有 创建函数updateGeo2(text,float4,float4)返回float作为$$ 后来 选择UpdateGeo2('区域',40.88,-90.56); 我明白了 错误:错误:function updateGeo2(

回答 2 投票 0

我正在尝试在返回布尔表达式的Postgres中编写PL/PGSQL函数。 目前,代码看起来像这样:

函数first_predicate和second_predicate存在并返回布尔值,但是我没有得到太多帮助,因为它们是用类似的东西定义的,

回答 1 投票 0



寻求有关 plprofiler 安装和配置的帮助

我已经安装了 plprofiler 工具,但是当我尝试通过下面的命令分析查询时,它给出错误“无效的连接选项数据库”。 plprofiler run --command "SELECT query" --

回答 1 投票 0

为什么这个多个“DO”块脚本在 DBeaver 中工作但在 pgAdmin 中失败?

我创建了一个要在 Postgres DB 上运行的脚本,只要打开自动提交,在 DBeaver 中运行时它就可以完美运行,但是当相同的脚本在 pgAdmin 中运行并打开自动提交时...

回答 1 投票 0

如何在 PL/pgSQL 中按行类型返回表

我正在尝试使用 PL/pgSQL (PostgreSQL 9.3) 实现一个函数,该函数返回与参数中的输入表具有相同结构的表。基本上,我想更新一个表,并返回一个

回答 1 投票 0

循环多次调用函数

我的 Postgres 8.3 数据库中有一个函数,它采用“key”变量作为参数。 我想为一系列键值调用此函数。 我试过这个,没用... 开始 对于我...

回答 3 投票 0

PostgreSQL 删除名称未知的约束

我有一个 SQL 脚本,需要删除几个约束并在最后恢复它们,但约束名称是自动生成的,并且每次运行脚本时都会不同。 我知道如何...

回答 2 投票 0

动态访问 PostgreSQL 函数中的列和转换数据类型

在 PostgreSQL 的自定义函数中,我可以访问 NEW 对象来检索特定列的值,例如: 新的描述 新城 本质上,这是代码中的静态引用 -

回答 1 投票 0

基于hstore键的动态INSERT语句

给出以下场景: 我有一个表,其中基本上包含 2 个相关列: 表名(文本) 数据(hstore) hstore 键对应于表引用的列...

回答 1 投票 0

动态SQL循环时处理结果

我有一堆表,其中有一个“stat”列(stat 表示状态;-) 我想要每个统计数据的计数,然后看看! 我的桌子看起来像这样 创建表a( a_id UUID 主键默认

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.