Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Unanswered: count function alternative in postgres

    Is there any alternative of mysql function COUNT(DISTINCT expr,[expr...]) in postgres. We get error if we

    write count like this count(distinct profile.id, profile.name, profile.age) but it works well in mysql.

    Reference url is given below

    MySQL :: MySQL 5.1 Reference Manual :: 11.12.1 GROUP BY (Aggregate) Functions

    Thanks

  2. #2
    Join Date
    Aug 2009
    Location
    Olympia, WA
    Posts
    337
    In postgres you'll need to do this.
    Code:
    SELECT COUNT( DISTINCT ROW(col1, col2, col3) )
    FROM foo

  3. #3
    Join Date
    Apr 2010
    Posts
    16
    postgres=# select count(*) from (select id,name from parent) a;
    count
    -------
    12
    (1 row)

    Or

    postgres=# select count(distinct(id,name) ) from parent;
    count
    -------
    12
    (1 row)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •