powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Как в этой процедуре прописать условие IF
3 сообщений из 3, страница 1 из 1
Как в этой процедуре прописать условие IF
    #35672949
dmitry@ru
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Всем привет!
Как в этой процедуре прописать условие IF?

CREATE OR REPLACE FUNCTION main.up_mainchld_list(IN idnum_main integer, IN fio character, OUT idnum_key integer, OUT idnum_main integer, OUT idnum_wtype integer, OUT wtype_name character, OUT idnum_ptype integer, OUT ptype_name character, OUT dateprop timestamp without time zone, OUT dateout timestamp without time zone, OUT placeout character, OUT fio character, OUT datebirth timestamp without time zone, OUT placebirth character, OUT sex bit, OUT reason text, OUT delete_status bit, OUT idnum_nation integer, OUT nation_name character, OUT idnum_citizen integer, OUT citizen_name character, OUT idnum_whack integer, OUT whack_name character, OUT seriapass character, OUT nomerpass character, OUT placepass character, OUT datepass timestamp without time zone, OUT kodpass character, OUT ldescription text, OUT marital text, OUT datein timestamp without time zone, OUT placein character, OUT army bit, OUT uid uuid, OUT idnum_user integer, OUT last_user_modify integer, OUT description text, OUT insert_date timestamp without time zone, OUT modify timestamp without time zone, OUT user_name character, OUT user_name_modify character, OUT d_act character, OUT dated timestamp without time zone, OUT d_act_s character, OUT datedd timestamp without time zone)
RETURNS SETOF record AS
$BODY$
SELECT idnum_key, idnum_main, idnum_wtype, wtype_name, idnum_ptype, ptype_name,
dateprop, dateout, placeout, fio, datebirth, placebirth, sex,
reason, delete_status,

idnum_nation, nation_name, idnum_citizen, citizen_name, idnum_whack, whack_name, seriapass, nomerpass, placepass,
datepass, kodpass, ldescription, marital, datein, placein, army,

uid, idnum_user, last_user_modify, description, insert_date, modify, user_name, user_name_modify, d_act, dated, d_act_s, datedd

FROM main.uv_mainchld_list_all
WHERE idnum_main = $1 AND fio ILIKE '%' || $2 || '%'
ORDER BY fio;
$BODY$
LANGUAGE 'sql' VOLATILE
COST 100
ROWS 1000;
...
Рейтинг: 0 / 0
Как в этой процедуре прописать условие IF
    #35672997
Dan Black
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
dmitry@ru,
1. Научитесь использовать тег SRC на этом форуме
2. Подумайте, как можно изменить эту ужасную функцию.

Ну а чтобы иметь возможность использовать IF Замените LANGUAGE 'sql' на LANGUAGE 'plpgsql' со всеми вытекающими последствиями
...
Рейтинг: 0 / 0
Как в этой процедуре прописать условие IF
    #35672998
dmitry@ru
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
dmitry@ru,


Сам спросил сам ответил :)

Вот как это будет выглядеть:


CREATE OR REPLACE FUNCTION main.up_main_list(integer, character, character, character, character)
RETURNS SETOF record AS
$BODY$ DECLARE
_result record;
_b record;
BEGIN

if $1 = 0 then
FOR _b IN

SELECT idnum_key, idnum_ps, fio, pstype_name, idnum_town, town_name, idnum_street, street_name, house, flat, flatcount, roomcount, general_square,
live_square, ndocum, ddocum, idnum_dtype, dtype_name, owner_status, pds, arch, delete_status, uid, idnum_user, last_user_modify, description,
insert_date, modify, user_name, user_name_modify

FROM main.uv_main_list_all
WHERE fio ILIKE '%' || $2 || and street_name ILIKE '%' || $3 || and house ILIKE '%' || $4 || and flat ILIKE '%' || $5 ||
ORDER BY fio
--LIMIT 300; --OFFSET 100;
LOOP

-- можно вставить код

SELECT
_b.idnum_key::integer,
_b.idnum_ps::integer,
_b.fio::bpchar,
_b.pstype_name::bpchar,
_b.idnum_town::integer,
_b.town_name:: bpchar,
_b.idnum_street::integer,
_b.street_name::bpchar,
_b.house::bpchar,
_b.flat::bpchar,
_b.flatcount::integer,
_b.roomcount::integer,
_b.general_square::numeric(6,2),
_b.live_square::numeric(6,2),
_b.ndocum::bpchar,
_b.ddocum::timestamp without time zone,
_b.idnum_dtype::integer,
_b.dtype_name::bpchar,
_b.owner_status::bit,
_b.pds::bit,
_b.arch::bit,
_b.delete_status::bit,
_b.uid::uuid,
_b.idnum_user::integer,
_b.last_user_modify::integer,
_b.description::text,
_b.insert_date::timestamp without time zone,
_b.modify::timestamp without time zone,
_b.user_name::bpchar,
_b.user_name_modify::bpchar

INTO _result;
RETURN NEXT _result;

END LOOP;
RETURN;

end if;


/* вызов функции
select * from main.up_main_list2(0,'','','','') as (idnum_key integer, idnum_ps integer, fio bpchar, pstype_name bpchar, idnum_town integer, town_name bpchar,
idnum_street integer, street_name bpchar, house bpchar, flat bpchar, flatcount integer, roomcount integer, general_square numeric(6,2),
live_square numeric(6,2), ndocum bpchar, ddocum timestamp without time zone, idnum_dtype integer, dtype_name bpchar, owner_status bit, pds bit, arch bit,
delete_status bit, uid uuid, idnum_user integer, last_user_modify integer, description text, insert_date timestamp without time zone, modify timestamp without time zone,
user_name bpchar, user_name_modify bpchar);
*/

END $BODY$
LANGUAGE 'plpgsql' STABLE SECURITY DEFINER
COST 100
ROWS 1000;

Всем спасибо. Тема закрыта.
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Как в этой процедуре прописать условие IF
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]