functions returning

From: Tomasz Myrta <jasiek(at)lamer(dot)pl>
To: pgsql-sql(at)postgresql(dot)org
Subject: functions returning
Date: 2001-09-17 08:56:08
Message-ID: 3BA5BAA8.18545A8@lamer.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi

I had to write big sql code returning max 10 rows (3 selects 7,10 and 13
joins,
mostly equi-joins - too long to include). I tried do solve this in
different ways:

1. create view

Look at simple test.sql in attachement. Just make psql -f test.sql. I
have PostgreSQL 7.1.2.
I'm used to C,C++, not to SQL and I can't understand why selecting 1 row
from K2 doesn't use index scan for only 1 row.

-> Index Scan using k_pkey on k k1 (cost=0.00..2.02 rows=1
width=8)
-> Index Scan using k_pkey on k k2 (cost=0.00..8.14 rows=10 width=8)

Second view - bla2 works much worse...
Does it correspond to my question about dynamic date which should be
static (pgsql-bugs)?

Views would be nice but only if we could send them params...

2. sql function
I tried to return _int4 (array of int) - enough for me, but...
how to make array of non-static int?
'{0,1,2}' works fine, but '{id_t,id_k}' not

3. pl/pgsql function
first step - create temp table (once per session)
second step - pl/pgsql clears and inserts into that table.
I think it's the best solution. It works really fast. I can split sql
into smaller pieces and work on them separately.

Does anyone know how to make function returning rows another way?

Regards,
Tomek

Attachment Content-Type Size
test.sql text/plain 1.8 KB

Browse pgsql-sql by date

  From Date Subject
Next Message Kovacs Baldvin 2001-09-17 12:54:51 Re: Number the lines
Previous Message Kovacs Baldvin 2001-09-17 08:47:51 Re: Part 2 of "Intentional, or a bug"....