Re: [Pgsql-ayuda] Crear funcion.

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Leonardo Boet Sánchez <boet(at)gtm(dot)tel(dot)etecsa(dot)cu>
Cc: pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx
Subject: Re: [Pgsql-ayuda] Crear funcion.
Date: 2003-05-30 02:16:56
Message-ID: 20030530021656.GF4541@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

On Thu, May 29, 2003 at 06:44:33PM -0400, Leonardo Boet Sánchez wrote:
> Buenas tardes, soy nuevo en el mundo de postgres.
> quisiera crear una funcion que me retorne un conjunto de registro. lo trato de hacer con el psql

test=> create table autor (id serial primary key, nombre text);
NOTICE: CREATE TABLE will create implicit sequence 'autor_id_seq' for SERIAL column 'autor.id'
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'autor_pkey' for table 'autor'
CREATE TABLE
test=> create table libro (id serial primary key, id_autor int4 references autor,
titulo text);
NOTICE: CREATE TABLE will create implicit sequence 'libro_id_seq' for SERIAL column 'libro.id'
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'libro_pkey' for table 'libro'
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
CREATE TABLE
test=> create function muestra_libros () returns setof record as 'select
nombre, titulo from autor join libro on (id_autor=autor.id)' language sql;
CREATE FUNCTION
test=> select * from muestra_libros() as foo(autor text, titulo text);
autor | titulo
---------------+----------------------------------
Don Knuth | The Art of Computing Programming
J.R.R.Tolkien | The Hobbit
J.R.R.Tolkien | The Lord of the Rings
(3 rows)

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Some men are heterosexual, and some are bisexual, and some
men don't think about sex at all... they become lawyers" (Woody Allen)

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Francisco Valladolid 2003-05-30 06:54:12 Re: [Pgsql-ayuda] OT: Caso SCO - Micro$oft / Linux - Unix
Previous Message Alvaro Herrera 2003-05-30 02:07:08 Re: [Pgsql-ayuda] Crear funcion.