Re: [SQL] Finding duplicated values

2004-10-22 Thread Christoph Haller
Kent Anderson wrote:

>  I have a few tables that have duplicated values from an import from a
> different database. I have two keys I tried to set as primary and got
> an error ERROR:  could not create unique index
> DETAIL:  Table contains duplicated values.Is there some join I can use
> to compare the hmhmkey, wmwmkey pairs against the table to find
> duplicate values? Each pair key should be unique but the old database
> was less than normalized.I was trying to use the code below but it
> returned no rows.SELECT hmhmkey, wmwmkey
> FROM   exceptions
> EXCEPT
> SELECT hmhmkey, wmwmkey FROM  exceptions;Any suggestions?Kent
> Anderson

You might want to search the [SQL] archive on the following topics
for more inspiration:

selecting duplicate records
Delete 1 Record of 2 Duplicate Records

Regards, Christoph



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

   http://archives.postgresql.org


Re: [SQL] Functions return a select in a table, which data type I

2004-10-22 Thread Markus Bertheau
Ð ÐÐÐ, 22.11.2004, Ð 00:07, Andrà Toscano ÐÐÑÐÑ:
> Hello, friends.
> 
> If anybody can help, how can I do a FUNCTION return a result from a 
> SELECT in a table in PostgreSQL?
> My Problem is the RETURN TYPE from a FUNCTION, I donÂt know what I have 
> to use to return the data as a select result.
> 
> Example:
> 
> 
> DROP FUNCTION ACADEMICO.teste(int4);
> 
> CREATE FUNCTION ACADEMICO.teste(int4)
> RETURNS ?
> AS
> '
> select cod_aluno, nome, cpf from ACADEMICO.TB_alunos
> 
> '
> LANGUAGE 'SQL';

CREATE TYPE foo_type AS (cod_aluno TEXT, nome TEXT, cpf TEXT);
CREATE FUNCTION bar(int4)
RETURNS SETOF foo_type
LANGUAGE 'SQL'
AS '
DECLARE
var_rec foo_type;
BEGIN
FOR var_rec IN SELECT cod_aluno, nome, cpf FROM table WHERE ... LOOP
RETURN NEXT var_rec;
END LOOP;
RETURN;
END;
';

-- 
Markus Bertheau <[EMAIL PROTECTED]>


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly