PostgreSQL: у запроса нет места назначения для данных результата в запросе с переменными - PullRequest
0 голосов
/ 28 апреля 2020

ОШИБКА: у запроса нет места назначения для данных результата

СОВЕТ: Если вы хотите отменить результаты SELECT, используйте вместо этого PERFORM.

КОНТЕКСТ: PL / pg SQL function inline_code_block строка 11 в SQL выписка


DO $$
DECLARE
id_renovacion integer := (select Id_renovacionContrato 
from BEA.DIM_RENOVACION_CONTRATO where upper(Desc_renovacionContrato) = 'UNDEFINED'); 

id_renovacionpending integer := (select Id_renovacionContrato 
from BEA.DIM_RENOVACION_CONTRATO where upper(Desc_renovacionContrato) = 'PENDING');


BEGIN

SELECT count(id_contrato) as id_cantidad,
                CASE    when count(id_contrato) = 0 THEN 'ImagesHappyMaritransparente1.png'
                             when count(id_contrato) is null THEN 'ImagesHappyMaritransparente1.png'
                             when count(id_contrato) = 1 THEN 'ImagesTITIhappymarycontratos-off-1_145.png'
                             when count(id_contrato) = 2 THEN 'ImagesTITIhappymarycontratos-off-2_145.png'
                             when count(id_contrato) = 3 THEN 'ImagesTITIhappymarycontratos-off-3_145.png'
                             when count(id_contrato) = 4 THEN 'ImagesTITIhappymarycontratos-off-4_145.png'
                             when count(id_contrato) = 5 THEN 'ImagesTITIhappymarycontratos-off-5_145.png'
                             when count(id_contrato) = 6 THEN 'ImagesTITIhappymarycontratos-off-6_145.png'
                             when count(id_contrato) = 7 THEN 'ImagesTITIhappymarycontratos-off-7_145.png'
                             when count(id_contrato) = 8 THEN 'ImagesTITIhappymarycontratos-off-8_145.png'
                             when count(id_contrato) = 9 THEN 'ImagesTITIhappymarycontratos-off-9_145.png'
                             when count(id_contrato) > 9 THEN 'ImagesTITIhappymarycontratos-off-9+_145.png'
                END
 FROM BEA.FACT_CONTRATOS
WHERE cantDiasDif > 0 AND Id_rangoContrato IN (id_renovacion, id_renovacionpending);

END 
$$

LANGUAGE plpgsql; ```

Ответы [ 2 ]

1 голос
/ 28 апреля 2020

Две проблемы я вижу в размещенном коде.

  1. create в коде. Я не уверен, почему у вас есть create в вашем анонимном блоке.

  2. У вас есть следующий SELECT в вашем блоке DO:

SELECT count(id_contrato) as id_cantidad,
                CASE    when count(id_contrato) = 0 THEN 'ImagesHappyMaritransparente1.png'
                             when count(id_contrato) is null THEN 'ImagesHappyMaritransparente1.png'
                             when count(id_contrato) = 1 THEN 'ImagesTITIhappymarycontratos-off-1_145.png'
                             when count(id_contrato) = 2 THEN 'ImagesTITIhappymarycontratos-off-2_145.png'
                             when count(id_contrato) = 3 THEN 'ImagesTITIhappymarycontratos-off-3_145.png'
                             when count(id_contrato) = 4 THEN 'ImagesTITIhappymarycontratos-off-4_145.png'
                             when count(id_contrato) = 5 THEN 'ImagesTITIhappymarycontratos-off-5_145.png'
                             when count(id_contrato) = 6 THEN 'ImagesTITIhappymarycontratos-off-6_145.png'
                             when count(id_contrato) = 7 THEN 'ImagesTITIhappymarycontratos-off-7_145.png'
                             when count(id_contrato) = 8 THEN 'ImagesTITIhappymarycontratos-off-8_145.png'
                             when count(id_contrato) = 9 THEN 'ImagesTITIhappymarycontratos-off-9_145.png'
                             when count(id_contrato) > 9 THEN 'ImagesTITIhappymarycontratos-off-9+_145.png'
                END
 FROM BEA.FACT_CONTRATOS
WHERE cantDiasDif > 0 AND Id_rangoContrato IN (id_renovacion, id_renovacionpending);

И вы не сохраняете возвращенный результат SELECT ни в одну переменную. Если вам не нужен результат SELECT, используйте PERFORM, как указано ниже:

PERFORM count(id_contrato) as id_cantidad,
                CASE    when count(id_contrato) = 0 THEN 'ImagesHappyMaritransparente1.png'
                             when count(id_contrato) is null THEN 'ImagesHappyMaritransparente1.png'
                             when count(id_contrato) = 1 THEN 'ImagesTITIhappymarycontratos-off-1_145.png'
                             when count(id_contrato) = 2 THEN 'ImagesTITIhappymarycontratos-off-2_145.png'
                             when count(id_contrato) = 3 THEN 'ImagesTITIhappymarycontratos-off-3_145.png'
                             when count(id_contrato) = 4 THEN 'ImagesTITIhappymarycontratos-off-4_145.png'
                             when count(id_contrato) = 5 THEN 'ImagesTITIhappymarycontratos-off-5_145.png'
                             when count(id_contrato) = 6 THEN 'ImagesTITIhappymarycontratos-off-6_145.png'
                             when count(id_contrato) = 7 THEN 'ImagesTITIhappymarycontratos-off-7_145.png'
                             when count(id_contrato) = 8 THEN 'ImagesTITIhappymarycontratos-off-8_145.png'
                             when count(id_contrato) = 9 THEN 'ImagesTITIhappymarycontratos-off-9_145.png'
                             when count(id_contrato) > 9 THEN 'ImagesTITIhappymarycontratos-off-9+_145.png'
                END
 FROM BEA.FACT_CONTRATOS
WHERE cantDiasDif > 0 AND Id_rangoContrato IN (id_renovacion, id_renovacionpending);

Однако, вопрос, почему вы хотите это сделать? Сообщите нам причину отказа от сохранения результатов SELECT или вашего намерения.

0 голосов
/ 29 апреля 2020

Этот код решает проблему, используйте таблицу CREATE для отображения результатов.

DO $$
DECLARE
id_renovacion integer := (select Id_renovacionContrato 
from BEA.DIM_RENOVACION_CONTRATO where upper(Desc_renovacionContrato) = 'UNDEFINED'); 

id_renovacionpending integer := (select Id_renovacionContrato 
from BEA.DIM_RENOVACION_CONTRATO where upper(Desc_renovacionContrato) = 'PENDING');


BEGIN

DROP TABLE if EXISTS  tbcontratos;
CREATE TABLE tbcontratos (id_cantidad integer, images varchar(200));

insert into tbcontratos
SELECT count(id_contrato) as id_cantidad,
                CASE    when count(id_contrato) = 0 THEN 'Images\HappyMari\transparente1.png'
                             when count(id_contrato) is null THEN 'Images\HappyMari\transparente1.png'
                             when count(id_contrato) = 1 THEN 'Images\TITI\happymary\contratos-off-1_145.png'
                             when count(id_contrato) = 2 THEN 'Images\TITI\happymary\contratos-off-2_145.png'
                             when count(id_contrato) = 3 THEN 'Images\TITI\happymary\contratos-off-3_145.png'
                             when count(id_contrato) = 4 THEN 'Images\TITI\happymary\contratos-off-4_145.png'
                             when count(id_contrato) = 5 THEN 'Images\TITI\happymary\contratos-off-5_145.png'
                             when count(id_contrato) = 6 THEN 'Images\TITI\happymary\contratos-off-6_145.png'
                             when count(id_contrato) = 7 THEN 'Images\TITI\happymary\contratos-off-7_145.png'
                             when count(id_contrato) = 8 THEN 'Images\TITI\happymary\contratos-off-8_145.png'
                             when count(id_contrato) = 9 THEN 'Images\TITI\happymary\contratos-off-9_145.png'
                             when count(id_contrato) > 9 THEN 'Images\TITI\happymary\contratos-off-9+_145.png'
                END
 FROM BEA.FACT_CONTRATOS
WHERE cantDiasDif > 0 AND Id_rangoContrato IN (id_renovacion, id_renovacionpending);



END 
$$

LANGUAGE plpgsql;

select id_cantidad, images from tbcontratos; ```
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...