Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVjCj-0006nE-F4 for pgsql-general@arkaria.postgresql.org; Sun, 31 Dec 2017 19:23:29 +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 1eVjCi-0004nn-Jq for pgsql-general@arkaria.postgresql.org; Sun, 31 Dec 2017 19:23:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eVjCh-0004nd-Uj for pgsql-general@lists.postgresql.org; Sun, 31 Dec 2017 19:23:28 +0000 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eVjCf-0003Si-3Q for pgsql-general@postgresql.org; Sun, 31 Dec 2017 19:23:26 +0000 Received: by mail-io0-x244.google.com with SMTP id q188so21282689iod.1 for ; Sun, 31 Dec 2017 11:23:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=0bea4303uQUymMJVIXdqk/2ZPoKVWheQ3FZ1tJxx/58=; b=dfZmEyQV10nuI4wIYu972InmpGWMNf/cOlhtRfTe39RKvt3i1WsTiKQwZRdFudJp+N dkGY3PmBOUGaPmtqa3gNQuQnsieSZuBHYUUNBiUgLrphD4sjXj1RNMkyp3dKfLN3TCCj tAUhlCDSqPUXYMZPvSJ9IJ2QAjjwT7A/rH7g6xaPq5tGuUH1mog45qLG5zofINaggXFZ +wdr18QWwcVJLzSz8Eklvt3LI2pFlWJGBmVOwu3mFhlg2r972ccv+qaCxmkUgx0Z97FQ g/QBY6q4ih4noXCZ4vLPNmmcJwSVJSVZoXgHOHRmhwl+FRqBkiENl8c3WqIOBT/voTSs eaOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=0bea4303uQUymMJVIXdqk/2ZPoKVWheQ3FZ1tJxx/58=; b=PftGX3CCUmRqJJM4q+FBzCJiDBj5hrA++0q6RHmTGkLv9lZ+iYmr/mLQUQViHkNiH2 J6Gj2aAeCF7zGWzuAFJBtOpuYuzs0b53/FR2U5oFDDm0WZu5Sjm5vvAXJdXnlpO1Owku O6uL3EMFDxU/aW4NWjU/JrYbgyl3kbrG3zbjTsG86WJRu+EMtvCQI7uWW21BWureBlkN p9dywKuawn/CO1wTdI0EnTbNuLqYFEAbHwfztlau94uINk5dWx6nAbgxWy7t3xxb8f4y pWabD8QYCMsWWlTH6uNkOi22Yhah4JCI8EsnBYy53QC9rLfjrxXdavhk8gcCEqY717co 209g== X-Gm-Message-State: AKGB3mJNi0JmZccoeX4Ffp7ogEDD/NsVN7sJgjFvfZoFvIT3nOACGd8k t062Z3DDNfFobnBPjGBOB8E= X-Google-Smtp-Source: ACJfBotfpCLOpKi8JsRWEq9Vful54Pv+L3Se73NiSMWWHm+ym52el/qI1s7tsjZkhssmO7mqeWnYBQ== X-Received: by 10.107.190.1 with SMTP id o1mr14369190iof.262.1514748204214; Sun, 31 Dec 2017 11:23:24 -0800 (PST) Received: from [172.31.99.94] (50-243-0-163-static.hfc.comcastbusiness.net. [50.243.0.163]) by smtp.gmail.com with ESMTPSA id a69sm15327170itc.18.2017.12.31.11.23.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Dec 2017 11:23:23 -0800 (PST) Content-Type: multipart/alternative; boundary=Apple-Mail-32C5DC40-BD38-4DF4-81B3-010955304D60 Mime-Version: 1.0 (1.0) Subject: Re: Find duplicates in a column then print Information to a file From: Rob Sargent X-Mailer: iPhone Mail (15C153) In-Reply-To: Date: Sun, 31 Dec 2017 12:23:21 -0700 Cc: Francisco Olarte , martin.moore@avbrief.com, pgsql-general@postgresql.org Content-Transfer-Encoding: 7bit Message-Id: References: To: Sherman Willden List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail-32C5DC40-BD38-4DF4-81B3-010955304D60 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Keep in mind there is a quick write-to-file in psql with =E2=80=98\o =E2=80=99. And don=E2=80=99t forget to turn it off with =E2=80=98\o=E2=80= =99 > On Dec 31, 2017, at 12:04 PM, Sherman Willden wr= ote: >=20 > Thank you for the replies. I will start working on them now. Not a student= but since I now have the time I may look into it. I am 71 retired working a= t Home Depot. I have a collection of CDs by various artists and I have the t= ime to create and maintain my own database concerning these subjects. I reti= red from USAF, SUN Microsystems, and HP where I worked with the UNIX systems= . As I said my main question right now is which duplicate songs do I have an= d who performs them. I really appreciate the support I get here. >=20 > Sherman >=20 >> On Sun, Dec 31, 2017 at 11:53 AM, Francisco Olarte wrote: >> Mmmmm, I notice a faint homework smell here ;-> , but the question is >> nicely asked so: >>=20 >> On Sun, Dec 31, 2017 at 7:19 PM, Sherman Willden >> wrote: >> ... >> > SELECT aria FROM aria_precis WHERE aria IN (SELECT aria FROM aria_preci= s >> > GROUP BY aria HAVING COUNT(aria)>1); >>=20 >> The outer select is fully redundant. Just use the inner one. In fact, >> not redundnat, harmful, as it will spit many copies of aria for the >> duplicated ones. If you add id (and/or artist) to the outer query then >> it is useful again. >>=20 >>=20 >> > When I perform the following I get (0 rows): >> > SELECT aria FROM aria_precis WHERE aria IN (SELECT aria FROM aria_preci= s >> > GROUP BY id, aria HAVING COUNT(aria)>1); >>=20 >> As expected. See the inner query, you are grouping by ID which is the >> primary key, by PK definition all counts are going to be one, so no >> results, nothing goes to the outer query. >>=20 >> Use the first query, but adding id and artist to the OUTER level. >>=20 >> > After I get the above information how do I write that information to a f= ile? >> > 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; >>=20 >> If copy format is ok to you, knowing \copy look at the docs, looking >> at https://www.postgresql.org/docs/9.6/static/app-psql.html you will >> read: >>=20 >> >>> >> \copy { table [ ( column_list ) ] | ( query ) } { from | to } { >> 'filename' | program 'command' | stdin | stdout | pstdin | pstdout } [ >> [ with ] ( option [, ...] ) ] >>=20 >> Performs a frontend (client) copy. This is an operation that runs an >> SQL COPY command, but instead of the server reading or writing the >> specified file, psql reads or writes the file and routes the data >> between the server and the local file system. This means that file >> accessibility and privileges are those of the local user, not the >> server, and no SQL superuser privileges are required. >> <<< >>=20 >> Notice the (query) option? Your copy is using the table+optional >> column list format, (aria_precis), just change it to the "( query )" >> format ( NOTICE THE MANDATORY PARENS, this is how copy knows what to >> do. "t" =3D> table, "t(c1)"=3D>table+columns, "(xx)" =3D> query ( nothing= >> before the opening parens ). ) >>=20 >> Happy new year. >>=20 >> Francisco Olarte. >=20 --Apple-Mail-32C5DC40-BD38-4DF4-81B3-010955304D60 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Keep in mind there is a qui= ck write-to-file in psql with =E2=80=98\o <filename>=E2=80=99. And don= =E2=80=99t forget to turn it off with =E2=80=98\o=E2=80=99

On D= ec 31, 2017, at 12:04 PM, Sherman Willden <operasopranos@gmail.com> wrote:

Thank you for the replies. I will s= tart working on them now. Not a student but since I now have the time I may l= ook into it. I am 71 retired working at Home Depot. I have a collection of C= Ds by various artists and I have the time to create and maintain my own data= base concerning these subjects. I retired from USAF, SUN Microsystems, and H= P where I worked with the UNIX systems. As I said my main question right now= is which duplicate songs do I have and who performs them. I really apprecia= te the support I get here.

Sherman

On Sun, Dec 31, 2017 at 11:53 AM, Fra= ncisco Olarte <folarte@peoplecall.com> wrote:
Mmmmm, I notice a faint homework smell here ;-> , b= ut the question is
nicely asked so:

On Sun, Dec 31, 2017 at 7:19 PM, Sherman Willden
<operasopranos@gmail.com&g= t; wrote:
...
> SELECT aria FROM aria_precis WHERE aria IN (SELECT ari= a FROM aria_precis
> GROUP BY aria  HAVING COUNT(aria)>1);

The outer select is fully redundant. Just use the inner one. In fact,=
not redundnat, harmful, as it will spit many copies of aria for the
duplicated ones. If you add id (and/or artist) to the outer query then
it is useful again.


> When I perform the following I get (0 rows):
> SELECT aria FROM aria_precis WHERE aria IN (SELECT aria FROM aria_preci= s
> GROUP BY id, aria  HAVING COUNT(aria)>1);

As expected. See the inner query, you are grouping by ID which is the=
primary key, by PK definition all counts are going to be one, so no
results, nothing goes to the outer query.

Use the first query, but adding id and artist to the OUTER level.

> After I get the above information how do I write that information to a f= ile?
> The only thing I know writes the entire database to a file:
>  \COPY aria_precis TO '/home/sherman/aria_precis_2.csv' WITH D= ELIMITER '#,'
> CSV HEADER;

If copy format is ok to you, knowing \copy look at the docs, looking<= br> at https://www.postgresql.org/docs/9.6/stat= ic/app-psql.html you will
read:

>>>
\copy { table [ ( column_list ) ] | ( query ) } { from | to } {
'filename' | program 'command' | stdin | stdout | pstdin | pstdout } [
[ with ] ( option [, ...] ) ]

Performs a frontend (client) copy. This is an operation that runs an
SQL COPY command, but instead of the server reading or writing the
specified file, psql reads or writes the file and routes the data
between the server and the local file system. This means that file
accessibility and privileges are those of the local user, not the
server, and no SQL superuser privileges are required.
<<<

Notice the (query) option? Your copy is using the table+optional
column list format, (aria_precis), just change it to the "( query )"
format ( NOTICE THE MANDATORY PARENS, this is how copy knows what to
do. "t" =3D> table, "t(c1)"=3D>table+columns, "(xx)" =3D> query ( n= othing
before the opening parens ). )

Happy new year.

Francisco Olarte.

= --Apple-Mail-32C5DC40-BD38-4DF4-81B3-010955304D60--