pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ERROR: SELECT query has no destination for result data
5+ messages / 4 participants
[nested] [flat]

* ERROR: SELECT query has no destination for result data
@ 2006-08-31 13:00 Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  2006-08-31 13:51 ` Re: ERROR: SELECT query has no destination for result data 2000 Informatica <2000info@netsite.com.br>
  2006-08-31 13:57 ` Re: ERROR: SELECT query has no destination for result data John DeSoi <desoi@pgedit.com>
  2006-08-31 14:21 ` Re: ERROR: SELECT query has no destination for result data Joe <dev@freedomcircle.net>
  0 siblings, 3 replies; 5+ messages in thread

From: Ezequias Rodrigues da Rocha @ 2006-08-31 13:00 UTC (permalink / raw)
  To: pgsql-sql

Hi list,

I have a function like this:

Create OR REPLACE Function base.inserirPontos(char(1), varchar(255),
numeric(12,2), int8, int8, int8 ) returns int4 as
$$
declare
    Operacao alias for $1;
    Numero_nota alias for $2;
    Valor_nota alias for $3;
    PontoVenda_Emissor alias for $4;
    Cardpass alias for $5;
    Cx_Id alias for $6;

begin

-- Validando parâmetros passados na função

  if Operacao <> 'C' then
     return 1;
   else
     select count(id) as numRegistros from base.emissor_ponto_venda where id
= PontoVenda_Emissor;
     if numRegistros = 0 then
        return 2;
      else
        insert into base.pontos values (nextval('base.ponto_id'), now(),
Operacao, Numero_nota, Valor_nota, PontoVenda_Emissor, CartaoId(Cardpass),
Cx_id);
        return 0;
     end if;
  end if;
end

$$
 LANGUAGE 'plpgsql'

And I am getting the following result when I try to insert using the
function:

select base.inserirPontos('C', '123456789', 12.5, 1, 9877000000944005, 104)


ERROR:  SELECT query has no destination for result data
HINT:  If you want to discard the results, use PERFORM instead.
CONTEXT:  PL/pgSQL function "inserirpontos" line 17 at SQL statement

What I did wrong ? Any suggestion is quite good please.

ps:

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                  Atenciosamente (Sincerely)
                        Ezequias Rodrigues da Rocha
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
A pior das democracias ainda é melhor do que a melhor das ditaduras
The worst of democracies is still better than the better of dictatorships
http://ezequiasrocha.blogspot.com/

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: ERROR: SELECT query has no destination for result data
  2006-08-31 13:00 ERROR: SELECT query has no destination for result data Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
@ 2006-08-31 13:51 ` 2000 Informatica <2000info@netsite.com.br>
  2 siblings, 0 replies; 5+ messages in thread

From: 2000 Informatica @ 2006-08-31 13:51 UTC (permalink / raw)
  To: pgsql-sql


Ezequias,

Declare a variavel  numRegistros dentro da funcao e altere o SELECT p/

     select count(id) INTO numRegistros from base.emissor_ponto_venda where id = PontoVenda_Emissor; 

q vai dar certo, OK ??


SPS
2000Info



  ----- Original Message ----- 
  From: Ezequias Rodrigues da Rocha 
  To: pgsql-sql@postgresql.org 
  Sent: Thursday, August 31, 2006 10:00 AM
  Subject: [SQL] ERROR: SELECT query has no destination for result data


  Hi list,

  I have a function like this:

  Create OR REPLACE Function base.inserirPontos(char(1), varchar(255), numeric(12,2), int8, int8, int8 ) returns int4 as 
  $$
  declare
      Operacao alias for $1;
      Numero_nota alias for $2;
      Valor_nota alias for $3;
      PontoVenda_Emissor alias for $4;
      Cardpass alias for $5;
      Cx_Id alias for $6; 

  begin

  -- Validando parâmetros passados na função

    if Operacao <> 'C' then
       return 1;
     else
       select count(id) as numRegistros from base.emissor_ponto_venda where id = PontoVenda_Emissor; 
       if numRegistros = 0 then
          return 2;          
        else
          insert into base.pontos values (nextval('base.ponto_id'), now(), Operacao, Numero_nota, Valor_nota, PontoVenda_Emissor, CartaoId(Cardpass), Cx_id); 
          return 0;   
       end if; 
    end if;
  end

  $$
   LANGUAGE 'plpgsql'

  And I am getting the following result when I try to insert using the function:

  select base.inserirPontos('C', '123456789', 12.5, 1, 9877000000944005, 104)


  ERROR:  SELECT query has no destination for result data
  HINT:  If you want to discard the results, use PERFORM instead.
  CONTEXT:  PL/pgSQL function "inserirpontos" line 17 at SQL statement 

  What I did wrong ? Any suggestion is quite good please.

  ps: 

  -- 
  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                    Atenciosamente (Sincerely) 
                          Ezequias Rodrigues da Rocha
  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  A pior das democracias ainda é melhor do que a melhor das ditaduras
  The worst of democracies is still better than the better of dictatorships 
  http://ezequiasrocha.blogspot.com/ 


------------------------------------------------------------------------------


  No virus found in this incoming message.
  Checked by AVG Free Edition.
  Version: 7.1.405 / Virus Database: 268.11.7/434 - Release Date: 30/8/2006

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: ERROR: SELECT query has no destination for result data
  2006-08-31 13:00 ERROR: SELECT query has no destination for result data Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
@ 2006-08-31 13:57 ` John DeSoi <desoi@pgedit.com>
  2006-08-31 14:26   ` Re: ERROR: SELECT query has no destination for result data John DeSoi <desoi@pgedit.com>
  2 siblings, 1 reply; 5+ messages in thread

From: John DeSoi @ 2006-08-31 13:57 UTC (permalink / raw)
  To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql


On Aug 31, 2006, at 9:00 AM, Ezequias Rodrigues da Rocha wrote:

> select count(id) as numRegistros from base.emissor_ponto_venda  
> where id = PontoVenda_Emissor;


declare numRegistros as an integer in the declarations section and  
rewrite the select:

select into numRegistros count(id) from base.emissor_ponto_venda  
where id = PontoVenda_Emissor;

See http://www.postgresql.org/docs/8.1/interactive/plpgsql- 
statements.html#PLPGSQL-SELECT-INTO




John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: ERROR: SELECT query has no destination for result data
  2006-08-31 13:00 ERROR: SELECT query has no destination for result data Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  2006-08-31 13:57 ` Re: ERROR: SELECT query has no destination for result data John DeSoi <desoi@pgedit.com>
@ 2006-08-31 14:26   ` John DeSoi <desoi@pgedit.com>
  0 siblings, 0 replies; 5+ messages in thread

From: John DeSoi @ 2006-08-31 14:26 UTC (permalink / raw)
  To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql

Sorry, try

select into numRegistros count(*) from base.emissor_ponto_venda where  
id = PontoVenda_Emissor;

The thing you are selecting into needs to match what you are  
selecting. So in your examples below, record is needed when you use  
"* from ...". If you just need to look at one value:

select into num_em_pdv id from base.emissor_ponto_venda where id =  
PontoVenda_Emissor;


John


On Aug 31, 2006, at 10:07 AM, Ezequias Rodrigues da Rocha wrote:

> Thank you John,
>
> It only works using records. I don't know why.
>
> When I put ('works well'):
> select into num_em_pdv * from base.emissor_ponto_venda where id =  
> PontoVenda_Emissor;
>          if num_em_pdv.id is null then --> Se o emissor ponto venda  
> passado não tem na base retorne 4
>             retorno:= 4;
>
> When I put (don't works well):
>     num_em_pdv int4;
> select into num_em_pdv * from base.emissor_ponto_venda where id =  
> PontoVenda_Emissor;
>          if num_em_pdv.id is null then --> Se o emissor ponto venda  
> passado não tem na base retorne 4
>             retorno:= 4;
>
> Reports the error:
> ERROR:  missing FROM-clause entry for table "num_em_pdv"
> CONTEXT:  SQL statement "SELECT  num_em_pdv.id is null"
> PL/pgSQL function "inserirpontos" line 30 at if
>
> Thank you John. I think I should stay with the record type.



John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: ERROR: SELECT query has no destination for result data
  2006-08-31 13:00 ERROR: SELECT query has no destination for result data Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
@ 2006-08-31 14:21 ` Joe <dev@freedomcircle.net>
  2 siblings, 0 replies; 5+ messages in thread

From: Joe @ 2006-08-31 14:21 UTC (permalink / raw)
  To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql

Ezequias Rodrigues da Rocha wrote:
> Hi list,
>
> I have a function like this:
>
> Create OR REPLACE Function base.inserirPontos(char(1), varchar(255), 
> numeric(12,2), int8, int8, int8 ) returns int4 as
> $$
> declare
>     Operacao alias for $1;
>     Numero_nota alias for $2;
>     Valor_nota alias for $3;
>     PontoVenda_Emissor alias for $4;
>     Cardpass alias for $5;
>     Cx_Id alias for $6;
>
> begin
>
> -- Validando parâmetros passados na função
>
>   if Operacao <> 'C' then
>      return 1;
>    else
>      select count(id) as numRegistros from base.emissor_ponto_venda 
> where id = PontoVenda_Emissor;
You haven't declared numRegistros.

Joe



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2006-08-31 14:26 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-31 13:00 ERROR: SELECT query has no destination for result data Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2006-08-31 13:51 ` 2000 Informatica <2000info@netsite.com.br>
2006-08-31 13:57 ` John DeSoi <desoi@pgedit.com>
2006-08-31 14:26   ` John DeSoi <desoi@pgedit.com>
2006-08-31 14:21 ` Joe <dev@freedomcircle.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox