[SQL] spi and error messages

2007-05-30 Thread Bart Degryse
Hi, I'm writing some function to fetch data from an Oracle database and store it in a PostgreSQL database. CREATE OR REPLACE FUNCTION public.replicate_billing(text, date, date) RETURNS void AS $body$ use DBI; my $dbh_ora = DBI->connect('dbi:Oracle:database=bmssa;host=firev120-1.indicator.b

Re: [SQL] spi and error messages

2007-05-30 Thread Michael Fuhr
On Wed, May 30, 2007 at 09:33:40AM +0200, Bart Degryse wrote: > In general how should I catch the error message generated if one > of the spi functions (spi_exec_query, spi_query, spi_fetchrow, > spi_prepare,...) fails? In PL/Perl functions you can use eval to catch errors just as you would in an

[SQL] logging amount rows retrieved?

2007-05-30 Thread Gerardo Herzig
Hi all. Im wondering if there is a way to include in the postgresql logs the total rows retrieved after a query (im logging the query itself right now). Something like apache does when it logs the amount of bytes retrieved after a GET. Thanks! Gerardo ---(end of broadc

[SQL] slow query execution

2007-05-30 Thread Trigve Siver
Hi all, This query executes very slow: select (select count(*) from customer where id <= a.id) as row, id, from customer as a order by id; Where customer has id column and others and has also index on id column. The table has about 10.000+ records. When used with "explain", it gives me this o

Re: [SQL] slow query execution

2007-05-30 Thread Andrew Sullivan
On Wed, May 30, 2007 at 08:56:45AM -0700, Trigve Siver wrote: > Hi all, > > This query executes very slow: > > select (select count(*) from customer where id <= a.id) as row, id, > from customer as a order by id; So you are trying to get the ordinal position of every ID in the table? I'm not su

Re: [SQL] slow query execution

2007-05-30 Thread Trigve Siver
Hi, Thanks for reply, As you have mentioned I need to get row numbers for my query, so when I make some other query with same data I will know which row number has a particular ID. As you mentioned "You can do this with a temporary sequence, among other approaches...". Can you point me to some

Re: [SQL] slow query execution

2007-05-30 Thread Rodrigo De León
On 5/30/07, Trigve Siver <[EMAIL PROTECTED]> wrote: Can you point me to some sources or give me some examples, please? CREATE OR REPLACE FUNCTION ROWNUM() RETURNS BIGINT AS $$ BEGIN RETURN NEXTVAL('ROWNUM_SEQ'); EXCEPTION WHEN OTHERS THEN CREATE T

Re: [SQL] slow query execution

2007-05-30 Thread Trigve Siver
Thanks a lot Trigve - Original Message From: Rodrigo De León <[EMAIL PROTECTED]> To: pgsql-sql@postgresql.org; Trigve Siver <[EMAIL PROTECTED]> Sent: Wednesday, May 30, 2007 7:28:47 PM Subject: Re: [SQL] slow query execution On 5/30/07, Trigve Siver <[EMAIL PROTECTED]> wrote: > Can you

Re: [SQL] slow query execution

2007-05-30 Thread Andrew Sullivan
On Wed, May 30, 2007 at 10:03:16AM -0700, Trigve Siver wrote: > Hi, Thanks for reply, As you have mentioned I need to get row > numbers for my query, so when I make some other query with same > data I will know which row number has a particular ID. Oh, wait. If _that's_ your plan, then this will

Re: [SQL] slow query execution

2007-05-30 Thread Trigve Siver
>- Original Message >From: Andrew Sullivan <[EMAIL PROTECTED]> >To: pgsql-sql@postgresql.org >Sent: Wednesday, May 30, 2007 7:39:18 PM >Subject: Re: [SQL] slow query execution > >On Wed, May 30, 2007 at 10:03:16AM -0700, Trigve Siver wrote: >> Hi, Thanks for reply, As you have mentioned I

Re: [SQL] slow query execution

2007-05-30 Thread Andrew Sullivan
On Wed, May 30, 2007 at 11:08:02AM -0700, Trigve Siver wrote: > I want to do it only for some queries. So when I need query like > that "SELECT * from t1" I need to add row_numbers there. So I will > have "query with row_numbers" (where row_numbers are row numbers of > my virtual list view). Then

Re: [SQL] slow query execution

2007-05-30 Thread Trigve Siver
>- Original Message >From: Andrew Sullivan <[EMAIL PROTECTED]> >To: pgsql-sql@postgresql.org >Sent: Wednesday, May 30, 2007 8:30:32 PM >Subject: Re: [SQL] slow query execution > >On Wed, May 30, 2007 at 11:08:02AM -0700, Trigve Siver wrote: > >> I want to do it only for some queries. So wh

Re: [SQL] slow query execution

2007-05-30 Thread Richard Huxton
Trigve Siver wrote: I seee...when new data will be added to table, then row numbers wouldn''t be valid anymore. Hmmm...looked like I need to find other solution. Try explaining what it is you're trying to achieve, and maybe someone will be able to suggest a solution. -- Richard Huxton

Re: [SQL] slow query execution

2007-05-30 Thread Trigve Siver
>- Original Message >From: Richard Huxton <[EMAIL PROTECTED]> >To: Trigve Siver <[EMAIL PROTECTED]> >Cc: pgsql-sql@postgresql.org >Sent: Wednesday, May 30, 2007 9:05:09 PM >Subject: Re: [SQL] slow query execution > >Trigve Siver wrote: >> >> I seee...when new data will be added to table,