Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eViHH-0002b0-QL for pgsql-general@arkaria.postgresql.org; Sun, 31 Dec 2017 18:24:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eViHH-0001j4-6M for pgsql-general@arkaria.postgresql.org; Sun, 31 Dec 2017 18:24:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eViHG-0001it-Qz for pgsql-general@lists.postgresql.org; Sun, 31 Dec 2017 18:24:07 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eViHD-0003eL-09 for pgsql-general@postgresql.org; Sun, 31 Dec 2017 18:24:06 +0000 Received: by mail-wr0-x244.google.com with SMTP id o101so16724638wrb.6 for ; Sun, 31 Dec 2017 10:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=avbrief-com.20150623.gappssmtp.com; s=20150623; h=user-agent:date:subject:from:to:message-id:thread-topic:references :in-reply-to:mime-version; bh=WmHjwdhtX3dNv2ZzohZfXM7M/FFmHrOwypDTimU2atM=; b=pba7/gojO5UJpA2LwraPSP9GZkOs3L8UUe6rg4ywj+1RBev/4PDwbzJq6yc9mkPMIa VZY6/3fN6Bm+WSQRNAL4k3MjI6Pr20ENPSyf3uA7emfibJwO8t/hRZpjZr1yiqdfxYpD 67P/XXfiiItwSf6gpu2oOQMm/BrqTJua16Y94dEDdYDDtFDl7fx+um6MUfvXON5M0jzB oqT/GUmHsOnIxeEEmaEdEqG7dINUL4YJ3og+FkiTJz5H0Df1wRuUENC0bsMq/g9QsZWQ BNqDskEt9ATr/tsdQu/mYKFisOhU7Y/yem/a6nUC53bbJnhDo6qkUci+DdxL5cXvlyPd zsGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:date:subject:from:to:message-id :thread-topic:references:in-reply-to:mime-version; bh=WmHjwdhtX3dNv2ZzohZfXM7M/FFmHrOwypDTimU2atM=; b=RVmjUCyM8NDEx/DRwGIUGaNmUmaiN1ajGw2wPZK/AVc8978IyggNO6+etFfoT/bA7P GhGriN7s4m65RaxK2V2QasPfIpAG9FtVqrspfGEY/VzIzc+9yBKcxcl/znA4RQfr2kQ+ q57PBJfArD7pwYmIJTkkJfZYRkEVx1ZGCIG0htYoJyabZpdAEGOe9bSIiNGENz3/Ouc2 +0EoQoxrjzD0RWeNqCeQbyzGuFI3KW4YwbXE5G6hhLf7hih7535eb8SooXILxKa+Y+KI sZU/cFGCQBRoJ6xfRCSVFVvEZzn8pDhKoAfpl1Uxe6i0RTyicoa9ebM7s5tQ0pb3/piA uq5g== X-Gm-Message-State: AKGB3mLiL5Lhf/8E1CHOJGTjmU+5wzhhTZ8GX9yFoHJDnpUpFV/BrLoc AzeE7I7JnluomltmZofE5lw+rw== X-Google-Smtp-Source: ACJfBou0qdJ2WMMfW/blqVhdD00Mw7kPaIN3+NhHiwrg7yCH0JsHFjg5ZcxJ77bVLaueM8zYhh5xeQ== X-Received: by 10.223.184.143 with SMTP id i15mr42179412wrf.31.1514744641500; Sun, 31 Dec 2017 10:24:01 -0800 (PST) Received: from [192.168.0.202] (cpc134188-nail4-2-0-cust164.know.cable.virginm.net. [77.99.14.165]) by smtp.gmail.com with ESMTPSA id r64sm62131479wrb.62.2017.12.31.10.24.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Dec 2017 10:24:00 -0800 (PST) User-Agent: Microsoft-MacOutlook/f.29.0.171205 Date: Sun, 31 Dec 2017 18:23:59 +0000 Subject: Re: Find duplicates in a column then print Information to a file From: Martin Moore To: Sherman Willden , Message-ID: Thread-Topic: Find duplicates in a column then print Information to a file References: In-Reply-To: Mime-version: 1.0 Content-type: multipart/alternative; boundary="B_3597589440_960241186" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3597589440_960241186 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable =20 From: Sherman Willden Date: Sunday, 31 December 2017 at 18:19 To: Subject: Find duplicates in a column then print Information to a file =20 Development Platform: Ubuntu 17.10 mainly command line work Tools: perl 5.26 and postgresql 9.6 Goal: Display duplicate aria titles on screen and to a local file Database name: arias Table name: aria_precis csv delimiter: the # symbol arias=3D# \d aria_precis Table "public.aria_precis" Column | Type | Modifiers -------------+------+----------- id | text | not null aria | text | artist | text | a_artist | text | album_title | text | Indexes: "aria_precis_pkey" PRIMARY KEY, btree (id) Problems: 1. Can't connect aria title to id 2. Can't write discovered information to file I know about this link but I probably didn't understand what I read there. https://www.postgresql.org/docs/current/static/sql-select.html#SQL-WITH What I know displays the 46 duplicate aria titles of 413 entries but not th= e id or artist: SELECT aria FROM aria_precis WHERE aria IN (SELECT aria FROM aria_precis GR= OUP BY aria HAVING COUNT(aria)>1); When I perform the following I get (0 rows): SELECT aria FROM aria_precis WHERE aria IN (SELECT aria FROM aria_precis GR= OUP BY id, aria HAVING COUNT(aria)>1); aria ------ (0 rows) After I get the above information how do I write that information to a file= ? The only thing I know writes the entire database to a file: \COPY aria_precis TO '/home/sherman/aria_precis_2.csv' WITH DELIMITER '#,'= CSV HEADER; Thank you; Sherman =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 =20 On the cmdline just do: =20 psql arias -c =E2=80=98SELECT aria FROM aria_precis WHERE aria IN (SELECT a= ria FROM aria_precis GROUP BY aria HAVING COUNT(aria)>1)=E2=80=98=C2=A0 =C2=A0> outfile.t= xt =20 =20 Martin. =20 =20 =20 =20 --B_3597589440_960241186 Content-type: text/html; charset="UTF-8" Content-transfer-encoding: quoted-printable

 

From: Sherman Willden <operasopranos@gmail.com>
Date: = Sunday, 31 December 2017 at 18:19
To: <pgsql-general@postgresql= .org>
Subject: Find duplicates in a column then print Informati= on to a file

 <= /o:p>

Development Platform: Ubuntu 17.10 ma= inly command line work

Tools: perl 5.26 and postgresql 9.6

Goa= l: Display duplicate aria titles on screen and to a local file

Databa= se name: arias

Table name: aria_precis

csv delimiter: the # sy= mbol

arias=3D# \d aria_precis
   Table "public.aria_p= recis"
   Column    | Type | Modifiers
-= ------------+------+-----------
 id     &nb= sp;    | text | not null
 aria    = ;    | text |
 artist      |= text |
 a_artist    | text |
 album_title | = text |
Indexes:
    "aria_precis_pkey" PRIMAR= Y KEY, btree (id)

Problems:
  1. Can't connect aria title to = id
  2. Can't write discovered information to file

I know abo= ut this link but I probably didn't understand what I read there.
https://www.postgresql.org/docs/current/static/sql-select.html= #SQL-WITH

What I know displays the 46 duplicate aria titles of 41= 3 entries but not the id or artist:
SELECT aria FROM aria_precis WHERE ar= ia IN (SELECT aria FROM aria_precis GROUP BY aria  HAVING COUNT(aria)&g= t;1);

When I perform the following I get (0 rows):
SELECT aria FRO= M aria_precis WHERE aria IN (SELECT aria FROM aria_precis GROUP BY id, aria&= nbsp; HAVING COUNT(aria)>1);
 aria
------
(0 rows)

A= fter I get the above information how do I write that information to a file? = The only thing I know writes the entire database to a file:
 \COPY a= ria_precis TO '/home/sherman/aria_precis_2.csv' WITH DELIMITER '#,' CSV HEAD= ER;

Thank you;

Sherman

=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

&nb= sp;

 

On t= he cmdline just do:

 

psql arias <pwd> -c =E2=80=98SELECT aria FROM aria_precis W= HERE aria IN (SELECT aria FROM aria_precis GROUP BY aria  HAVING COUNT(= aria)>1)=E2=80=98=C2=A0 =C2=A0> outfile.txt

&n= bsp;

 

Mar= tin.

 

 

 

 

--B_3597589440_960241186--