dbTalk Databases Forums  

using 'count' to show number of dupes

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss using 'count' to show number of dupes in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Andy Harrison
 
Posts: n/a

Default using 'count' to show number of dupes - 07-12-2004 , 12:28 PM






I'm writing some perl to sendmail maillog reporting. Since the logs
are too big to some of the things I want to do, I'm just stuffing it
to a pgsql db. I'd like to offload as much of the work onto the db as
much as possible.

How can I use count to show rows with the same value in the column?

col1 col2 col3
foo1 bar1 baz1
foo2 bar1 baz2
foo3 bar2 baz3
foo4 bar3 baz4
foo5 bar1 baz5
foo6 bar2 baz6


So, what would get pg to show me that col2 has 3 'bar1' values, 2
'bar2' values and 1 'bar1' value.

--
Andy Harrison

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #2  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: using 'count' to show number of dupes - 07-12-2004 , 12:39 PM







On Mon, 12 Jul 2004, Andy Harrison wrote:

Quote:
I'm writing some perl to sendmail maillog reporting. Since the logs
are too big to some of the things I want to do, I'm just stuffing it
to a pgsql db. I'd like to offload as much of the work onto the db as
much as possible.

How can I use count to show rows with the same value in the column?

col1 col2 col3
foo1 bar1 baz1
foo2 bar1 baz2
foo3 bar2 baz3
foo4 bar3 baz4
foo5 bar1 baz5
foo6 bar2 baz6


So, what would get pg to show me that col2 has 3 'bar1' values, 2
'bar2' values and 1 'bar1' value.
Something like:
select col2, count(*) from table group by col2;

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
  #3  
Old   
Loftis, Charles E
 
Posts: n/a

Default Re: using 'count' to show number of dupes - 07-12-2004 , 12:50 PM



Write a queries like this...

SELECT col1, count(col1) as count_col1
FROM <table>
GROUP BY col1


-----Original Message-----
From: pgsql-novice-owner (AT) postgresql (DOT) org
[mailtogsql-novice-owner (AT) postgresql (DOT) org] On Behalf Of Andy Harrison
Sent: Monday, July 12, 2004 1:29 PM
To: pgsql-novice (AT) postgresql (DOT) org
Subject: [NOVICE] using 'count' to show number of dupes


I'm writing some perl to sendmail maillog reporting. Since the logs are too
big to some of the things I want to do, I'm just stuffing it to a pgsql db.
I'd like to offload as much of the work onto the db as much as possible.

How can I use count to show rows with the same value in the column?

col1 col2 col3
foo1 bar1 baz1
foo2 bar1 baz2
foo3 bar2 baz3
foo4 bar3 baz4
foo5 bar1 baz5
foo6 bar2 baz6


So, what would get pg to show me that col2 has 3 'bar1' values, 2 'bar2'
values and 1 'bar1' value.

--
Andy Harrison

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org


Reply With Quote
  #4  
Old   
Andy Harrison
 
Posts: n/a

Default Re: using 'count' to show number of dupes - 07-12-2004 , 01:02 PM



On Mon, 12 Jul 2004 10:39:00 -0700 (PDT), Stephan Szabo
<sszabo (AT) megazone (DOT) bigpanda.com> wrote:
Quote:
Something like:
select col2, count(*) from table group by col2;

Great, thanx. That got me on the right road. Fast too. Several mere
seconds for 1.25M rows.

--
Andy Harrison

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.