Re: Function, that returns set of 2 tables columns

From: "Willy-Bas Loos" <willybas(at)gmail(dot)com>
To: "Ron Johnson" <ron(dot)l(dot)johnson(at)cox(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Function, that returns set of 2 tables columns
Date: 2007-02-13 14:55:23
Message-ID: 1dd6057e0702130655n192c08cbvccd2bdc16a29ece3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>Creating a view might work.
Yeah, if all you use is SELECT, you should probably use a view, then you
don't need to specify the output columns in the calling statement, only a
WHERE clause.
Othrewise, it's the same thing:
SELECT * FROM myview WHERE field1=10;

Views are transparant in postgresql, so you need not worry that at first
your backend will load the whole view and then filter your results
(performance-wise).

On 2/13/07, Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 02/13/07 07:46, Dmitriy Chumack wrote:
> > Hi *
> >
> > I need to write a function, that returns a set of all columns from 2
> > tables.
> [snip]
> > for i in select * from "Table1", "Table2"
> > loop
> > return next i;
> > end loop;
> [snip]
> >
> > This two tables have about 20 columns together, so I don't want list
> > them each I call this function. Can I achieve this in some other
> > (right) way?
> >
> > P.S. I don't want to create a specific type for this purpose, but
> > if there is no other way, I should.
>
> What do these tables join on?
>
> Creating a view might work.
>
> CREATE VIEW V_SIDE_BY_SIDE AS
> SELECT T1.*, T2.*
> FROM TABLE1 T1,
> TABLE2 T2
> WHERE T1.PK = T2.PK;
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFF0ck4S9HxQb37XmcRAjPEAJ9qaHwa5mbKiFVqcfEZbPXIX7GmIwCgzvvs
> zCPM45xZ590kv2xXnIoSsqM=
> =NkbJ
> -----END PGP SIGNATURE-----
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Cristiano Panvel 2007-02-13 15:04:16 Re: PostgreSQL and OpenLdap
Previous Message Peter Eisentraut 2007-02-13 14:54:49 Re: Keyword OWNED not recognized in pg v. 8.1