agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: SQL conversion help
Date: Mon, 22 May 2017 08:30:50 +0200
Message-ID: <ofu0ik$qo$1@blaine.gmane.org> (raw)
In-Reply-To: <025d01d2d11d$cb2ebba0$618c32e0$@1nar.com.tr>
References: <025d01d2d11d$cb2ebba0$618c32e0$@1nar.com.tr>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
Ertan Küçükoğlu schrieb am 20.05.2017 um 06:01:
> I have below SQL script used in SQL Server. I would like some help to
> convert it into PostgreSQL format, please.
>
> DECLARE @satirno INT
> SET @satirno = 0
> UPDATE urtrecetedet
> SET @satirno = satirno = @satirno + 1
> WHERE recetekodu = 'ASD'
Assuming your primary key column is named ID, you can do it like this:
update urtrecetedet u
set satirno = t.rn
from (
select id,
row_number() over (order by id) as rn
from urtrecetedet
where recetekodu = 'ASD'
) t
where t.id = u.id;
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (5+ messages)
Message-ID: <ofu0ik$qo$1@blaine.gmane.org>
Permalink: ../ofu0ik$qo$1@blaine.gmane.org/
Also on: postgresql.org/message-id/ofu0ik$qo$1@blaine.gmane.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: SQL conversion help
In-Reply-To: <ofu0ik$qo$1@blaine.gmane.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox