Re: [SQL] Function to either return one or all records

2005-04-20 Thread KÖPFERL Robert
Hmmm, you're right. Is there any way to do a explain select * from id_val_tbl where false while explain doesn't tell SEQ_SCAN? I have to admit that I didn't performance tested this. I just saw explain writing SEQ_SCAN. |-Original Message- |From: Tom Lane [mailto:[EMAIL PROTECTED] |Sent:

Re: [SQL] checking pgsql functions

2005-04-20 Thread Michael Fuhr
On Thu, Apr 21, 2005 at 04:35:37AM +0200, Enrico Weigelt wrote: > > Is it possible to check plpgsql functions before they're actually > into the database, as it's done w/ sql functions ? What version of PostgreSQL are you using? 8.0 and later have a validator function for PL/pgSQL, although its

Re: [SQL] checking pgsql functions

2005-04-20 Thread Tom Lane
Enrico Weigelt <[EMAIL PROTECTED]> writes: > Is it possible to check plpgsql functions before they're actually > into the database, as it's done w/ sql functions ? 8.0 does a little bit of this, and 8.1 will do more... regards, tom lane ---(end of

[SQL] checking pgsql functions

2005-04-20 Thread Enrico Weigelt
Hi folks, Is it possible to check plpgsql functions before they're actually into the database, as it's done w/ sql functions ? Often I've got the problem that a function still contains some syntax errors (well, nobody's perfect), but my application is quite critical (a single crashing trigger m

Re: [SQL] Function to either return one or all records

2005-04-20 Thread Tom Lane
"Tambet Matiisen" <[EMAIL PROTECTED]> writes: > Standard technique is to rewrite OR queries to UNION queries. I believe > PostgreSQL optimizer does not do that automatically. So you could try instead: > select * from id_bal_tbl where $1 is null > union all > select * from id_bal_tbl where id = $1

Re: [SQL] Function to either return one or all records

2005-04-20 Thread Tambet Matiisen
> > CREATE OR REPLACE FUNCTION getval(integer) > RETURNS SETOF id_val_tbl AS > $BODY$ > select * from id_bal_tbl where ( $1 is null )or (id=$1 ); $BODY$ > LANGUAGE 'sql' VOLATILE SECURITY DEFINER; > > > It works fine, however an index is never used (if just one > record is requested). The c

Re: [SQL] Query question

2005-04-20 Thread Franco Bruno Borghesi
If you have a row every 15 seconds, the answer is quite easy: SELECT A1.date FROM activity A1 LEFT JOIN activity A2 ON (A2.date=A1.date-'15 secs'::interval) WHERE A1.state<>A2.state OR A2.state IS NULL ORDER BY 1 Now if you don't have a row every 15 seconds, the answer is a bit more

[SQL] Query question

2005-04-20 Thread Stéphane RIFF
Hi , I have table that represent a switch activity like this : | date| state | | 2005-04-20 17:00:00 | 0 | | 2005-04-20 17:00:15 | 0 | | 2005-04-20 17:00:30 | 1 | | 2005-04-20 17:00:45 | 1 | | 2005-04-20 17:01:00 | 1 | | 2005-04-20 17:01:15

Re: [SQL] Odd error message (" hash indexes do not support whole-index scans")

2005-04-20 Thread Tom Lane
Marinos Yannikos <[EMAIL PROTECTED]> writes: > Shouldn't PostgreSQL behave in a different way in this case? (e.g. just > not use the index): Good catch. But why are you using a hash index for this? regards, tom lane ---(end of broadcast)-

[SQL] Odd error message (" hash indexes do not support whole-index scans")

2005-04-20 Thread Marinos Yannikos
Shouldn't PostgreSQL behave in a different way in this case? (e.g. just not use the index): Table "public.forum_messages" message_id | integer | not null default nextval('forum_messages_message_id_seq'::text) parent_userid

Re: [SQL] Debet-Credit-Balance Calculation

2005-04-20 Thread Chris Browne
[EMAIL PROTECTED] ("Muhyiddin A.M Hayat") writes: >> There is an easy way to do this; write a plpgsql set returning >> function which adds the balance to the last column of the table. That >> query will always have a cost in both time and memory proportional to >> the size of the table, and the me

Re: [SQL] Debet-Credit-Balance Calculation

2005-04-20 Thread Muhyiddin A.M Hayat
There is an easy way to do this; write a plpgsql set returning function which adds the balance to the last column of the table. That query will always have a cost in both time and memory proportional to the size of the table, and the memory cost may bite you as table size grows... -- Can you give

Re: [SQL] Debet-Credit-Balance Calculation

2005-04-20 Thread Muhyiddin A.M Hayat
There is an easy way to do this; write a plpgsql set returning function which adds the balance to the last column of the table. That query will always have a cost in both time and memory proportional to the size of the table, and the memory cost may bite you as table size grows... -- Can you give

[SQL] Function to either return one or all records

2005-04-20 Thread KÖPFERL Robert
Hi all, I think I have got a usual problem. I'm asking here, however, because I wonder why it works this way. The problem is to write a fcn that eihter returns all records or just one/none filtered by some expression. For example get a value by id or return all values if the given id is null. F