8

I've to help migrating a SQL Server 2008 database to a PostgreSQL 9.4.10 one. The original querys have SET NOCOUNT ON and SET NOCOUNT OFF several times, and I can't change this fact so ignoring the number of rows affected isn't a solution. That's why I need to find an equivalent to this statement, but all I can find are really old posts where they say I should ignore the result. Any ideas? Thanks.

EDIT: these SET NOCOUNTare inside a stored procedure that goes like this:

CREATE PROCEDURE [procedureName]
Declares

--Variables 

WITH ENCRYPTION
AS
SET NOCOUNT ON

--Procedure's code

SET NOCOUNT OFF
GO

As I've said this code isn't mine, so I can't post any of it more than the source of my doubt.

Luana Melina
  • 83
  • 1
  • 7
  • 1
    Those "really old posts" are right: just remove those statements. There is nothing equivalent in Postgres and it's not needed –  Dec 28 '16 at 15:58
  • 1
    you say "I can't change this fact " - what fact you can't change? The code? – Vao Tsun Dec 28 '16 at 16:02
  • 1
    if you speak about ignoring the number of rows returned, shown by the client, the closest would probably be `-t` for `psql`, but I don't understand why you would need it - can you please populate several examples of what you want to mock up?.. – Vao Tsun Dec 28 '16 at 16:06
  • I don't understand why they need it too, it's not my db. I'm just requested to translate it. I can't change the fact that the SQL Server DB uses nocount :S I know they might be right, but since I only found 2000's post I thought that the newer versions might have changed this or have a way too emulate it. Thanks a lot for the replies! – Luana Melina Dec 28 '16 at 17:27
  • In order to find an equivalent for some piece of code, you need to understand what that code is used for; just as translating a foreign sentence can't be done if you look at it word by word. In this instance, what output do you need to produce? Is the row count being captured somewhere? – IMSoP Dec 28 '16 at 17:41
  • You can't run that code on Postgres without changing it. And as you **have** to change the code, you can as well just remove the unnecessary parts while doing that. –  Dec 28 '16 at 17:41
  • @IMSoP I've been told that the software they use with this DB doesn't work when the number of rows affected are returned. – Luana Melina Dec 28 '16 at 18:00
  • @a_horse_with_no_name that doesn't help my problem, but thanks for answering me! – Luana Melina Dec 28 '16 at 18:01
  • So all you need is to have the row count *off*? In that case, I think the Postgres equivalent is "do nothing", because it doesn't return the row count as part of the data stream in the same way anyway. Have you actually tried it and found any errors? – IMSoP Dec 28 '16 at 18:41
  • I can't try on the software because I don't have it, but I didn't know they weren't in the same data stream. Thanks a lot @IMSoP ! – Luana Melina Dec 28 '16 at 18:46
  • 2
    So you've been asked to write some code that you can't test? Sounds like a recipe for pain. You have my sympathy! – IMSoP Dec 28 '16 at 23:23

0 Answers0