From: | JimmyJ <rdinh(at)hotmail(dot)fr> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Rename entries with an increment |
Date: | 2014-10-01 10:46:56 |
Message-ID: | 1412160416664-5821237.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi, here is my issue. I have a table containing names. If a name appears
several times, I would like to rename it to add an incremented number to it.
For example, if 'Peter' appears three times in the table, I would like to
rename the first 'Peter' entry to 'Peter-1', the second one to 'Peter-2' and
so on. However, I began to do something but this doesn't seem to work at all
^^. Could someone please help me ? Thanks :)
DECLARE num int;
UPDATE test.suscribers
SET p_name = CONCAT(p_name,'-',num)
WHERE p_name=
(
SELECT name
FROM
(
SELECT *
FROM
(
SELECT test.suscribers.p_name AS nom, COUNT(*) AS nb
FROM test.suscribers
GROUP BY test.suscribers.p_name
)
AS table1
WHERE nb>1 AND wagaa != ''
)
AS table2
)
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Rename-entries-with-an-increment-tp5821237.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2014-10-01 15:48:59 | Re: Rename entries with an increment |
Previous Message | Merlin Moncure | 2014-09-30 22:03:26 | Re: setting query timeout as part of the query |