Re: [SQL] Add a ROWCOUNT to the output of a select.

2008-05-14 Thread Marcin Stępnicki
On Wed, May 14, 2008 at 1:54 AM, Gavin 'Beau' Baumanis
<[EMAIL PROTECTED]> wrote:
> Hi Everyone,
>
> After spending some time searching through our good friend Mr. Google and
> the mailing list I found a post that provided me with a query that does just
> what I need.

I think that this should be helpful:

http://www.depesz.com/index.php/2007/08/17/rownum-anyone-cumulative-sum-in-one-query/

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Add a ROWCOUNT to the output of a select.

2008-05-14 Thread Harald Fuchs
In article <[EMAIL PROTECTED]>,
"Robins Tharakan" <[EMAIL PROTECTED]> writes:

> While we could always check for the query performance reasons, I
> rather think that this is an overkill for the purpose of mere line
> numbers.

> If such queries don't change frequently, you could be better off
> using a simple function that instead adds a 'rownumber' field to the
> output of the inner SQL query. The 'rownumber' could instead be
> calculated by simply incrementing it within a FOR loop for each row.

I think a sequence is much simpler:

create temp sequence tmp;
select nextval('tmp') as rownum,
contactdate
from
myTable
where
contactdate > '2007-06-30 23:59:59'
order by
contactdate;


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Add a ROWCOUNT to the output of a select.

2008-05-14 Thread Marcin Stępnicki
On Wed, May 14, 2008 at 10:40 AM, Harald Fuchs
<[EMAIL PROTECTED]> wrote:
> I think a sequence is much simpler:
>
> create temp sequence tmp;
> select nextval('tmp') as rownum,
>contactdate
> from
>myTable
> where
>contactdate > '2007-06-30 23:59:59'
> order by
>contactdate;

I used to do it this way myself, but the solution in my previous post
is really worth the trouble.

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Add a ROWCOUNT to the output of a select.

2008-05-14 Thread Robins Tharakan
Oops!
Of course, I meant a sequence.

*Robins*

On Wed, May 14, 2008 at 2:10 PM, Harald Fuchs <[EMAIL PROTECTED]>
wrote:

> In article <[EMAIL PROTECTED]>,
> "Robins Tharakan" <[EMAIL PROTECTED]> writes:
>
> > While we could always check for the query performance reasons, I
> > rather think that this is an overkill for the purpose of mere line
> > numbers.
>
> > If such queries don't change frequently, you could be better off
> > using a simple function that instead adds a 'rownumber' field to the
> > output of the inner SQL query. The 'rownumber' could instead be
> > calculated by simply incrementing it within a FOR loop for each row.
>
> I think a sequence is much simpler:
>
> create temp sequence tmp;
> select nextval('tmp') as rownum,
> contactdate
> from
>myTable
> where
>contactdate > '2007-06-30 23:59:59'
> order by
>contactdate;
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


Re: [SQL] Auto-formatting timestamps?

2008-05-14 Thread Peter Koczan
On Tue, May 13, 2008 at 5:54 PM, Mag Gam <[EMAIL PROTECTED]> wrote:
> Why not create a view?

That's a possibility, but the issue is that the output formatting is
bound to a data type (timestamp), not one or two particular tables.
Trying to create a view for all the tables with timestamps (and
creating appropriate rules for updating views) would be a huge
administrative PITA.

> > Hi all,
> >
> > I'm undergoing a port from an old Sybase database to Postgres. It's
> > going surprisingly well, but I have a question regarding formatting of
> > timestamps.
> >
> > In Sybase, we get:
> > :> select date from checkoutdate;
> > date
> > 'May  1 2001 12:00AM'
> > ...
> >
> > In Postgres:
> > => select date from checkoutdate;
> >   date
> > -
> >  2001-05-01 00:00:00
> > ...
> >
> > I can properly format it using to_char:
> > => select to_char(date, 'Mon DD  HH:MIAM') as date from checkoutdate;
> >   date
> > -
> >  May 01 2001 12:00AM
> > ...
> >
> > Short of creating a wrapper type for timestamp (which seems like
> > overkill just for modifying the output function), is there a way to
> > output the Sybase format automatically (i.e. without a call to
> > to_char)?
> >
> > I've found some code that actually somewhat depends on this format,
> > and one of my goals in this port is to change as little client code as
> > possible. Is it possible to automatically change the output like this,
> > preferably on a per-connection basis? I found stuff regarding the
> > datestyle parameter in the docs, but that doesn't quite do what I'd
> > like.
> >
> > Thanks much,
> > Peter

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Auto-formatting timestamps?

2008-05-14 Thread Alvaro Herrera
Peter Koczan escribió:
> On Tue, May 13, 2008 at 5:54 PM, Mag Gam <[EMAIL PROTECTED]> wrote:
> > Why not create a view?
> 
> That's a possibility, but the issue is that the output formatting is
> bound to a data type (timestamp), not one or two particular tables.
> Trying to create a view for all the tables with timestamps (and
> creating appropriate rules for updating views) would be a huge
> administrative PITA.

If you're really set about that, you can add a new DateStyle setting.
It's a bit of C hacking.  (Or you can hire someone to do it for you.)

-- 
Alvaro Herrerahttp://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Auto-formatting timestamps?

2008-05-14 Thread Mag Gam
But why not make a view similar to, select * from checkoutdate do select *
from checkoutdate_special_view

You don't have to do it for each table, you just do it for your source
table, and use the view to manipulate stuff...

If you have many tables like that, you can create a view for each of them,
sure its a lot of work, but its worth it

HTH


On Wed, May 14, 2008 at 11:46 AM, Peter Koczan <[EMAIL PROTECTED]> wrote:

> On Tue, May 13, 2008 at 5:54 PM, Mag Gam <[EMAIL PROTECTED]> wrote:
> > Why not create a view?
>
> That's a possibility, but the issue is that the output formatting is
> bound to a data type (timestamp), not one or two particular tables.
> Trying to create a view for all the tables with timestamps (and
> creating appropriate rules for updating views) would be a huge
> administrative PITA.
>
> > > Hi all,
> > >
> > > I'm undergoing a port from an old Sybase database to Postgres. It's
> > > going surprisingly well, but I have a question regarding formatting of
> > > timestamps.
> > >
> > > In Sybase, we get:
> > > :> select date from checkoutdate;
> > > date
> > > 'May  1 2001 12:00AM'
> > > ...
> > >
> > > In Postgres:
> > > => select date from checkoutdate;
> > >   date
> > > -
> > >  2001-05-01 00:00:00
> > > ...
> > >
> > > I can properly format it using to_char:
> > > => select to_char(date, 'Mon DD  HH:MIAM') as date from
> checkoutdate;
> > >   date
> > > -
> > >  May 01 2001 12:00AM
> > > ...
> > >
> > > Short of creating a wrapper type for timestamp (which seems like
> > > overkill just for modifying the output function), is there a way to
> > > output the Sybase format automatically (i.e. without a call to
> > > to_char)?
> > >
> > > I've found some code that actually somewhat depends on this format,
> > > and one of my goals in this port is to change as little client code as
> > > possible. Is it possible to automatically change the output like this,
> > > preferably on a per-connection basis? I found stuff regarding the
> > > datestyle parameter in the docs, but that doesn't quite do what I'd
> > > like.
> > >
> > > Thanks much,
> > > Peter
>


[SQL] Query tuning

2008-05-14 Thread kapil.munish
Hi,





I have a query which is run across 3 tables JOB_TYPE_FIRST,
JOB_TYPE_SECOND and JOB_ALLOCATION_WORKLIST.



The column JOBID is referenced in JOB_ALLOCATION_WORKLIST table and
primary key in both JOB_TYPE_FIRST, JOB_TYPE_SECOND tables.



There is one more column BOOK_ID which is supplied as the binding
parameter to the query. The query looks like:



select count(distinct(j.JOBID)) as jobCount

from  JOB_TYPE_FIRST a, JOB_TYPE_SECOND b, JOB_ALLOCATION_WORKLIST j

where (( a.JOBID = j.JOBID)

and (a.BOOK_ID = :bookId))

or ((b.JOBID = j.JOBID)

and (b.BOOK_ID = :bookId));



As the records in the database are too large it is having huge cost and
stalling the server and takes lot of time.



Can anyone suggest a better way to fetch the results for the query or
tune it? Any help would be highly appreciated.





Thanks & Regards,

Kapil


Please do not print this email unless it is absolutely necessary. 

The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email. 

www.wipro.com