plpgsql

How to fix generating proper value type for INPUT parameter in jOOQ for generated user-defined PL/pgSQL function using <forcedType> tag?

↘锁芯ラ 提交于 2020-08-20 12:20:29
问题 I'm having an issue with resolving issue with <forcedType> for stored function written in PL/pgSQL in my generated Routines. This question is more specific for solving problem I had already asked in this question and answer is partially provided in this Q&A. This is ONE of my user-defined functions in PL/pgSQL which I'm having issue with (I'm displaying only one since both functions have same RETURN TYPE and INPUT parameter ): create or replace function public.get_order_by_order_id(o_id

FOR EACH STATEMENT trigger example

落爺英雄遲暮 提交于 2020-08-02 05:55:39
问题 I've been looking at the documentation of postgresql triggers, but it seems to only show examples for row-level triggers, but I can't find an example for a statement-level trigger. In particular, it is not quite clear how to iterate in the update/inserted rows in a single statement, since NEW is for a single record. 回答1: OLD and NEW are null or not defined in a statement-level trigger. Per documentation: NEW Data type RECORD ; variable holding the new database row for INSERT / UPDATE

Setting a customized option in a stored procedure

夙愿已清 提交于 2020-07-22 22:26:14
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution

Setting a customized option in a stored procedure

最后都变了- 提交于 2020-07-22 22:21:54
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution

Setting a customized option in a stored procedure

ⅰ亾dé卋堺 提交于 2020-07-22 22:19:16
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution

How to return a value from a stored procedure (not function)?

跟風遠走 提交于 2020-07-22 05:41:31
问题 I have a Stored Procedure that inserts, updates or deletes tablerows. It was working fine while all parameters were used as input. However, I need to return the ID of last inserted row. For that I tried using an INOUT parameter and RETURNING after the INSERT statement to return the ID. However, I am not sure how to bind the returned ID to the INOUT parameter. Following is the code for stored procedure: CREATE OR REPLACE PROCEDURE public.spproductinsertupdatedelete( _ser integer, _subcategid

It could refer to either a PL/pgSQL variable or a table column

那年仲夏 提交于 2020-07-18 03:12:49
问题 I have a function in pgsql CREATE OR REPLACE FUNCTION core.date_bs_from_ad(date_in_ad date) RETURNS character varying AS $$ BEGIN RETURN( SELECT date_in_bs FROM core.date_conversion WHERE date_in_ad = $1 ); END $$ LANGUAGE plpgsql; It is created with no errors, but when i use this function it through following error: ERROR: column reference "date_in_ad" is ambiguous LINE 3: WHERE date_in_ad = $1 ^ DETAIL: It could refer to either a PL/pgSQL variable or a table column. QUERY: SELECT ( SELECT

How to create function that returns nothing

二次信任 提交于 2020-07-16 17:01:33
问题 I want to write a function with pl/pgsql . I'm using PostgresEnterprise Manager v3 and using shell to make a function, but in the shell I must define return type. If I don't define the return type, I'm not able to create a function. How can create a function without return result, i.e a Function that creates a new table? 回答1: Use RETURNS void like below: CREATE FUNCTION stamp_user(id int, comment text) RETURNS void AS $$ #variable_conflict use_variable DECLARE curtime timestamp := now();

How to perform SELECT query of PL/pgSQL user-defined function in jOOQ which returns JSON type?

人走茶凉 提交于 2020-07-10 10:27:06
问题 I'm having issue with finding right way to cast my user-defined function in PL/pgSQL into jOOQ code. My user-defined function in PL/pgSQL returns JSON type and I need to somehow adjust/cast it in jOOQ. I've Googled examples, but found none. Just in case here is my user-defined function in PL/pgSQL: create or replace function public.get_order_by_order_id(o_id bigint) returns json as $BODY$ DECLARE total_oi_price double precision; book_price double precision; total_price double precision; oi

Below is the psql code in which I am having syntax error. I am trying to create a trigger function on my test_route database

China☆狼群 提交于 2020-07-03 13:26:42
问题 CREATE OR REPLACE FUNCTION nearest_segment_insert() RETURNS trigger AS DECLARE id_temp integer; $BODY$ BEGIN IF OLD.id = NULL THEN select test_route.id into id_temp,ST_Distance(test_route.the_geom,NEW.the_geom) FROM test_route, ORDER BY 2 ASC LIMIT 1; UPDATE SET p.edges_id = r.id, p.the_geom = r.the_geom, p.dist_val = r.distance, r.distance = -1 FROM test_route r, road_block p, WHERE id_temp = r.id ; END IF; RETURN NEW; END; $BODY$ I am getting error "syntax error at or near "BEGIN". 回答1: The