Re: [SQL] two sums in one query

2005-07-13 Thread Ramakrishnan Muralidharan
I have assuemed that the row will having eighter Debit account or Credit account, the following Query will give sum of debit and credit accounts SELECT SUM( CASE WHEN COALESCE( DEBIT , 0 ) <> 0 THEN COALESCE( AMOUNT , 0 ) ELSE 0 END ) AS DEBIT_AMT , SUM( CASE WHEN COALE

Re: [SQL] index row size 2728 exceeds btree maximum, 2713

2005-06-05 Thread Ramakrishnan Muralidharan
Hi,   The issue looks like your Index width exceeds the maximum width  of the index key limit, Please review the keys used in the index.   Regards, R.Muralidharan     -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Din

Re: [SQL] Multiple SRF parameters from query

2005-06-05 Thread Ramakrishnan Muralidharan
Hi, I am not able to understand "Returning only one row", since 'aaa' having 2 rows and 'bbb' having 3 rows and what criteria single row should be returned. Please let me know the expected result and I will try to find out a solution for it. for set returning function the following link ma

Re: [SQL] index row size 2728 exceeds btree maximum, 2713

2005-06-05 Thread Ramakrishnan Muralidharan
, R.Muralidharan -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Dinesh PandeySent: Thursday, January 01, 2004 3:14 PMTo: Ramakrishnan Muralidharan; pgsql-general@postgresql.org; 'PostgreSQL'Subject: Re: [SQL] index row size 2728 exc

Re: [SQL] Convert int to hex

2005-06-05 Thread Ramakrishnan Muralidharan
Hi, You can use to_hex() function to convert integer to hexa number. I have tried with a small example. create table testing( id int4 , sHex varchar( 20 ) ) insert into testing( id ) values( 204678 ); insert into testing( id ) values( 2076876 ); update testing set sHex = ( cast( to_hex( id

Re: [SQL] Impossible with pl/pgsql?

2005-05-31 Thread Ramakrishnan Muralidharan
Hi, I have tried it on PostgreSQL 8.0.3 and following query gives the result SELECT ( DECORATE( FIND )).* FROM FIND() Regards, R.Muralidharan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Monday, May 30, 2005 8:46

Re: [SQL] CASCADE and TRIGGER - Some weird problem

2005-05-17 Thread Ramakrishnan Muralidharan
Hi, The issue is due to records in Account_message is still exists for the records which are going to be deleted from the Message table. Please check the sequence of deleting the records. When I tried to delete a record using your example, the following exception is raised. ERROR: update o

Re: [SQL] Select of a function that returns a array

2005-05-06 Thread Ramakrishnan Muralidharan
CREATE or replace FUNCTION mean_and_variancepop(var_table varchar, var_col varchar) RETURNS float8[] AS $$ DECLARE a float; b float; BEGIN a = 1.02; b =3.05; RETURN ARRAY[a,b]; END; $$ LANGUAGE plpgsql; -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] B

Re: [SQL] Record Log Trigger

2005-05-06 Thread Ramakrishnan Muralidharan
Hi, I do not think there is a performance issue due trigger on a larger database. For improving performance, it is better to write triggers for Insert, update, delete separately rather than combining them on a single trigger. Periodic VACCUM and RE-INDEX the table will improve the performan

Re: [SQL] can someone jelp me on this?

2005-05-06 Thread Ramakrishnan Muralidharan
Hi, Your mail just contain the database studcture and project spec. and nothing about the problem. Please let me know what help you are looking for? Regards, R.Muralidharan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Lord Knight of the Black Rose

Re: [SQL] trigger/rule question

2005-05-06 Thread Ramakrishnan Muralidharan
MAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Enrico Weigelt Sent: Monday, May 02, 2005 9:02 AM To: pgsql-sql Subject: Re: [SQL] trigger/rule question * Ramakrishnan Muralidharan <[EMAIL PROTECTED]> wrote: Hi, > Going through you mail, I assume that you are updating the mtime >

Re: [SQL] select within aggregate?

2005-05-06 Thread Ramakrishnan Muralidharan
Hi create table abc ( remote_hostvarchar(50),request_urivarchar(50),ts timestamp ); SELECT abc.remote_host , c , abc.request_uri , a.t FROM abc , ( select remote_host , count(*) as c , max( ts ) as t from abc group by remote_host ) as a where a.remote_host = abc.remote_host and abc.t

Re: [SQL] Function or Field?

2005-05-06 Thread Ramakrishnan Muralidharan
Hi I have tried with the following example CREATE TABLE products( id serial primary key, description varchar(50) ); CREATE TABLE vendding( id serial primary key, date_ date, product integer ); insert into products values ( 1 , 'Test product 1' ); insert into products values (

Re: [SQL] trigger/rule question

2005-04-29 Thread Ramakrishnan Muralidharan
Hi, Going through you mail, I assume that you are updating the mtime only after inserting the record. It is always possible to check the mtime filed value of the inserted record and take action based on it in the trigger. Is it possible to send me detail about the trigger? Regards, R.

Re: [SQL] people who buy A, also buy C, D, E

2005-04-29 Thread Ramakrishnan Muralidharan
Hi I am bit confused.. If you want to display first 5 the following query will fetch top 5 book id's. I am not able to understand, why there is a sub-query. SELECT ELEMENT_ID , COUNT( * ) FROM WATCH_LIST_ELEMENT GROUP BY ELEMENT_ID ORDER BY COUNT(*) DESC LIMIT 5 Regards, R.Muralidhar

Re: [SQL] Looking for a way to sum integer arrays....

2005-04-29 Thread Ramakrishnan Muralidharan
Hi, CREATE OR REPLACE FUNCTION SUM_ARR( aArr1 Integer[] , aArr2 Integer[] ) RETURNS Integer[] AS $$ DECLARE aRetu Integer[]; BEGIN -- Initialize the Return array with first array value. FOR i IN array_lower( aArr1 )..array_upper( aArr1 ) LOOP array_append( aRetu , aArr1[i] ); END L

Re: [SQL] UPDATE WITH ORDER BY

2005-04-29 Thread Ramakrishnan Muralidharan
Hi,       To my knowledge it is not possible to sort and update the code in a single update statement. I have done it through a simple function. I have given the function below.   CREATE OR REPLACE FUNCTION SortCode()RETURNS INT4 AS $$DECLARE  rRec RECORD;BEGIN  PERFORM SE

Re: [SQL] SQL subquery (count distinct) - Any Ideas?

2005-04-22 Thread Ramakrishnan Muralidharan
Hi I have modified the SQL query given by you and I hope the query given below will give you the correct count. SELECT U.USER_ID , U.NAME , COUNT(*) FROM USER U , CALL C , CALLER_SESSION CS WHERE C.CALLER_SESSION_ID = CS.CALLER_SESSION_ID AND U.USER_ID = CS.USER_ID AND CAST( CS.SESSION_D

Re: [SQL] Debet-Credit-Balance Calculation

2005-04-22 Thread Ramakrishnan Muralidharan
   Hi,      Using a table with larger data in the sub-query always eats up CPU time and it is time consuming. The below given statement uses the transaction table two times in the sub-query and for processing every record, it have to go through the same table twice in the sub-query.  I

Re: [SQL] SQL group select question

2005-04-22 Thread Ramakrishnan Muralidharan
Hi, The following SQL query will fetch you result based on the example given below, SELECT T.ID , T.VALUE FROM ( SELECT MAX( NUMB ) AS NUMB , NAME FROM TEST3 GROUP BY NAME ) AS A , TEST3 T WHERE A.NAME = T.NAME AND A.NUMB = T.NUMB ORDER BY T.ID DESC Regards, R.Muralidharan -

Re: [SQL] string to date conversion

2005-04-22 Thread Ramakrishnan Muralidharan
Hi, I have tried the same in PostgreSQL 8.0.1 and it is working fine. I have used following example for testing create table test1 ( date varchar(10) ) insert into test1 values('2005/04/22') select date::timestamp from test1 Regards, R.Muralidharan -Original Message-

Re: [SQL] 'Select INTO" in Execute (dynamic query )

2005-04-22 Thread Ramakrishnan Muralidharan
Hi,       It is not possible to access a local variable in EXECUTE Command and give a syntax error. FOR..IN..LOOP is the best option     CREATE OR REPLACE FUNCTION TestQry( vCon teXt )    RETURNS VARCHAR AS $$    DECLARE