plpgsql

Is there a convention for named arguments in a function in PostgreSQL

空扰寡人 提交于 2020-08-24 07:01:28
问题 I come from a SQL Server background where the '@' symbol is used/encouraged in stored procedures. This is useful because you can easily see what is a column and what is a value. For example. CREATE PROCEDURE Foo @Bar VARCHAR(10), @Baz INT AS BEGIN INSERT INTO MyTable ( Bar, Baz) VALUES ( @Bar, @Baz) END I know that I can just use ordinal position but some of our stored procs have 20 or so parameters and the named parameter makes it much more legible IMO. Is there some sort of convention that

How to declare an array of rowtype in a PostgreSQL function?

不打扰是莪最后的温柔 提交于 2020-08-23 03:54:17
问题 I am trying to create a PostgreSQL function where I will loop over the rows of a query and store some of them in an array, before doing more stuff with it. How can I create an array of rowtype? CREATE OR REPLACE FUNCTION forExample() RETURNS integer AS $BODY$ DECLARE r "WEBHOST"%rowtype; b "WEBHOST"%rowtype[]; <- This does not work !!! BEGIN FOR r IN SELECT * FROM "WEBHOST" LOOP array_append(b, r); END LOOP; RETURN 33; END $BODY$ LANGUAGE 'plpgsql'; The above function will be more complex,

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:21:07
问题 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