pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Function .. AS..?
3+ messages / 3 participants
[nested] [flat]

* Function .. AS..?
@ 2005-02-09 20:57  Ing. Jhon Carrillo <jdigital@cantv.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Ing. Jhon Carrillo @ 2005-02-09 20:57 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org; +Cc: pgsql-sql

Those instructions are good but i want  to call this function  only  for  " select  consulta_contacto(1)"  nothing more,  Is really necesary to use  "AS ..."?

this is  the call:


select * from  consulta_contacto(1) as (cont_codigo      integer, 
                                        cont_idpers      varchar,
                                        cont_nombre      varchar,
                                        cont_apellido    varchar,
                                        cont_titulo      varchar,
                                        cont_fecnac      timestamp ,
                                        cont_codedociv   integer,
                                        cont_sexo        char(1), 
                                        cont_codpais     integer,
                                        cont_pw          varchar,
                                        cont_empr        varchar,
                                        cont_cargo       varchar,
                                        cont_pwempr      varchar,
                                        cont_aniv        char(5),
                                        cont_prof        varchar,
                                        cont_trab        char(1),
                                        cont_fecgen      timestamp,
                                        cont_fecing      timestamp,
                                        cont_fuente      char(1),
                                        cont_sinc        char(1),
                                        cont_codupload   integer);

this is the function:


CREATE OR REPLACE FUNCTION consulta_contacto(integer) RETURNS SETOF RECORD AS '
DECLARE
   rec RECORD;
   sup INTEGER;
BEGIN
   FOR rec IN SELECT cont_codigo,cont_idpers, cont_nombre,cont_apellido,cont_titulo,cont_fecnac,cont_codedociv,cont_sexo,cont_codpais,cont_pw,cont_empr,cont_cargo,cont_pwempr,cont_aniv,cont_prof,cont_trab,cont_fecgen,cont_fecing,cont_fuente,cont_sinc,cont_codupload
      FROM tbu_contacto
     LOOP
       RETURN NEXT rec ;
     END LOOP;
   RETURN ;
END;
' LANGUAGE plpgsql;

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

* Re: Function .. AS..?
@ 2005-02-10 06:06  Stephan Szabo <sszabo@megazone.bigpanda.com>
  parent: Ing. Jhon Carrillo <jdigital@cantv.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Stephan Szabo @ 2005-02-10 06:06 UTC (permalink / raw)
  To: Ing. Jhon Carrillo <jdigital@cantv.net>; +Cc: pgsql-hackers@postgresql.org; pgsql-sql

On Wed, 9 Feb 2005, Ing. Jhon Carrillo wrote:

> Those instructions are good but i want to call this function only for "
> select consulta_contacto(1)"  nothing more, Is really necesary to use
> "AS ..."?

If it absolutely needs to be setof record, yes.

It may be more appropriate to make a composite type with CREATE TYPE AS
and then make the function return SETOF <newtypename> instead.



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

* Re: [SQL] Function .. AS..?
@ 2005-02-10 06:16  Michael Fuhr <mike@fuhr.org>
  parent: Ing. Jhon Carrillo <jdigital@cantv.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Michael Fuhr @ 2005-02-10 06:16 UTC (permalink / raw)
  To: Ing. Jhon Carrillo <jdigital@cantv.net>; +Cc: pgsql-hackers@postgresql.org; pgsql-sql

On Wed, Feb 09, 2005 at 04:57:14PM -0400, Ing. Jhon Carrillo wrote:

> Those instructions are good but i want  to call this function only
> for " select  consulta_contacto(1)" nothing more, Is really necesary
> to use  "AS ..."?
> 
> this is  the call:
> 
> select * from  consulta_contacto(1) as (cont_codigo      integer, 
>                                         cont_idpers      varchar,
>                                         ...

Instead of declaring the function to return SETOF RECORD, you could
return SETOF typename, where "typename" is the name of a composite
type or a table; your queries could then omit "AS ...."

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



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


end of thread, other threads:[~2005-02-10 06:16 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-09 20:57 Function .. AS..? Ing. Jhon Carrillo <jdigital@cantv.net>
2005-02-10 06:06 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2005-02-10 06:16 ` Michael Fuhr <mike@fuhr.org>

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