Re: More on unique vs distinct

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: stafford(at)marine(dot)rutgers(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: More on unique vs distinct
Date: 2006-11-20 23:16:56
Message-ID: DD7418CA-CA9A-4345-A19D-EB0659A00369@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Nov 21, 2006, at 5:27 , Wm.A.Stafford wrote:

> I guess I should have been a bit more specific. Here is an example
> of the type of query I'm finding in the Oracle app and the results
> of my attempt to find a PostgreSQL equivalent.
>
> select count(unique 'source_id') from obis_sources;
> pgAdmin III query responds:
> ERROR: syntax error at or near "'source_id'" at character 23
>
> select count(distinct 'source_id') from obis_sources;
> pgAdmin III query responds:
> ERROR: could not identify an equality operator for type "unknown"

I think the single quotes are the cause of your problem. Single-
quotes indicate a string literal. In the first case, you can see that
the syntax error is putting double quotes around 'source_id',
including the single quotes, because it's expecting an identifier
(not a string literal). In the second case it's seeing a string
literal but it's not sure what type to implicitly cast it to.

In either case, I think what you're looking for is:

select count(distinct source_id) from obis_sources;

Michael Glaesemann
grzm seespotcode net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-11-20 23:47:03 Re: PostgreSQL equivalent of the Oracale 'unique' qualifier
Previous Message Scott Marlowe 2006-11-20 23:13:32 Re: PostgreSQL equivalent of the Oracale 'unique'