Skip to content

Add ExecuteType parameter for reliable RETURNING clause support#13

Merged
jefim merged 7 commits intomainfrom
copilot/fix-insert-returning-value
Dec 2, 2025
Merged

Add ExecuteType parameter for reliable RETURNING clause support#13
jefim merged 7 commits intomainfrom
copilot/fix-insert-returning-value

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

Fix INSERT RETURNING clause support in PostgreSQL ExecuteQuery

Problem

INSERT statements with RETURNING clauses only return AffectedRows instead of the actual returned column values.

Solution

Added an explicit ExecuteType parameter (similar to MicrosoftSQL task) that allows users to control how queries are executed:

  • Auto (default): Automatically detects if the query returns data by checking FieldCount after execution
  • ExecuteReader: Explicitly execute queries that return data (SELECT or INSERT/UPDATE/DELETE with RETURNING)
  • NonQuery: Explicitly execute commands without returning data (INSERT/UPDATE/DELETE without RETURNING)

This approach is more reliable than string parsing and gives users explicit control.

Changes

  1. Created ExecuteTypes enum with Auto, ExecuteReader, and NonQuery options
  2. Added ExecuteType property to Input class with Auto as default
  3. Updated ExecuteQuery logic to use switch statement based on ExecuteType
  4. Fixed transaction handling to only use transactions for write operations
  5. Fixed reader disposal to occur before transaction commit
  6. Improved transaction disposal with using statements for proper cleanup
  7. Fixed whitespace formatting issues for superlinter compliance
  8. Bumped version to 2.0.0
  9. Updated CHANGELOG.md with comprehensive release notes documenting all added features, changes, and fixes
  10. Added tests for explicit ExecuteType usage

Testing

All 8 tests pass:

  • Existing tests continue to work with Auto mode (default)
  • New tests validate explicit ExecuteReader and NonQuery modes
  • Tests verify INSERT/UPDATE/DELETE with RETURNING clauses work correctly

Why This Solution is Better

  • No string parsing: Checks FieldCount instead of searching for keywords
  • Explicit control: Users can specify ExecuteReader for RETURNING clauses
  • Backward compatible: Default Auto mode maintains existing behavior
  • Follows established pattern: Mirrors Frends.MicrosoftSQL.ExecuteQuery approach

Version

This release is version 2.0.0 with full documentation in CHANGELOG.md for users to understand the new features and improvements.

Original prompt

Task full name: [Frends.PostgreSQL.ExecuteQuery.PostgreSQL.ExecuteQuery 1.0.1]
Task version: [1.0.1]
Summary:

Using the Tasks for INSERT and specifying returning a column, returns only information of AffectedRows and not the specified return value
Expected behaviour:

{value of the returning column}
Actual behaviour:

{
"QueryResult": {
"AffectedRows": 1
}
}
Steps to reproduce:

insert into {{#env.Shared_XXX.db_table_name}} (
column_a,
column_b,
column_c,
column_d,
column_e
)
VALUES (
'VALUE A',
'VALUE B',
'VALUE C,
'VALUE D',
'VALUE E'
)
returning column_f;


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

…ffectedRows

Co-authored-by: jefim <1387820+jefim@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with INSERT returning column value Fix RETURNING clause to return column values instead of AffectedRows Nov 26, 2025
Copilot AI requested a review from jefim November 26, 2025 06:47
@jefim
Copy link
Contributor

jefim commented Nov 26, 2025

@copilot ok, the query parsing and asking if it contains a "returning" word seems like not a very reliable thing, e.g. if some table name also contains this word. would there be a better solution?

Copilot AI and others added 3 commits November 26, 2025 07:04
Co-authored-by: jefim <1387820+jefim@users.noreply.github.com>
Co-authored-by: jefim <1387820+jefim@users.noreply.github.com>
Co-authored-by: jefim <1387820+jefim@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot ok, the query parsing and asking if it contains a "returning" word seems like not a very reliable thing, e.g. if some table name also contains this word. would there be a better solution?

You're absolutely right. I've replaced the string parsing approach with a more robust solution:

  1. Added an ExecuteType parameter (similar to MicrosoftSQL task) with Auto, ExecuteReader, and NonQuery options
  2. Auto mode (default) checks the actual FieldCount from the reader after execution, not the query text
  3. Users can explicitly set ExecuteType = ExecuteTypes.ExecuteReader for RETURNING queries if they want deterministic behavior

This eliminates false matches from table names or other text containing "returning".

Changes in commits: bd84334, 9421ca6, 8829925

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /usr/bin/curl curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)
  • https://api.github.com/repos/FrendsPlatform/Frends.MicrosoftSQL/contents/Frends.MicrosoftSQL.ExecuteQuery/Frends.MicrosoftSQL.ExecuteQuery/Definitions
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)
  • https://api.github.com/repos/FrendsPlatform/Frends.MicrosoftSQL/git/trees/cc51e76c0ecb76c120dd673261d2c73fb9a498a9
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix RETURNING clause to return column values instead of AffectedRows Add ExecuteType parameter for reliable RETURNING clause support Nov 26, 2025
@jefim
Copy link
Contributor

jefim commented Nov 26, 2025

@copilot We need to fix these superlinter errors

2025-11-26 07:26:21 [INFO] Stderr contents for CSHARP:

/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(130,94): error WHITESPACE: Fix whitespace formatting. Replace 20 characters with '

\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(132,63): error WHITESPACE: Fix whitespace formatting. Replace 10 characters with '
\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(152,94): error WHITESPACE: Fix whitespace formatting. Replace 20 characters with '

\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(154,44): error WHITESPACE: Fix whitespace formatting. Replace 10 characters with '
\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(182,94): error WHITESPACE: Fix whitespace formatting. Replace 20 characters with '

\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(184,44): error WHITESPACE: Fix whitespace formatting. Replace 10 characters with '
\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(205,94): error WHITESPACE: Fix whitespace formatting. Replace 20 characters with '

\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(207,45): error WHITESPACE: Fix whitespace formatting. Replace 10 characters with '
\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(228,94): error WHITESPACE: Fix whitespace formatting. Replace 20 characters with '

\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/ExecuteQueryTests.cs(230,39): error WHITESPACE: Fix whitespace formatting. Replace 10 characters with '
\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery.Tests/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery/ExecuteQuery.cs(65,51): error WHITESPACE: Fix whitespace formatting. Replace 44 characters with '

\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery/ExecuteQuery.cs(80,22): error WHITESPACE: Fix whitespace formatting. Replace 1 characters with '\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery/]
/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery/ExecuteQuery.cs(80,49): error WHITESPACE: Fix whitespace formatting. Replace 44 characters with '

\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s'. [/github/workspace/Frends.PostgreSQL.ExecuteQuery/Frends.PostgreSQL.ExecuteQuery/]


Co-authored-by: jefim <1387820+jefim@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot We need to fix these superlinter errors

...

Fixed all whitespace formatting issues. Removed trailing whitespace from blank lines in both ExecuteQueryTests.cs and ExecuteQuery.cs.

Changes in commit: 4f62ec1

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /usr/bin/curl curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@jefim
Copy link
Contributor

jefim commented Dec 2, 2025

@copilot Ok, now this looks good. We neew to bump the major version number in csproj and add an entry for this task's users in CHANGELOG.md, stating what changes have been made.

Co-authored-by: jefim <1387820+jefim@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 2, 2025

@copilot Ok, now this looks good. We neew to bump the major version number in csproj and add an entry for this task's users in CHANGELOG.md, stating what changes have been made.

Version bumped to 2.0.0 in csproj and CHANGELOG.md updated with detailed description of all changes including:

  • Added ExecuteType parameter with Auto, ExecuteReader, and NonQuery options
  • Fixed INSERT/UPDATE/DELETE with RETURNING clause support
  • Modified query execution logic and transaction handling
  • All improvements and fixes documented

Changes in commit: 0568b7b

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /usr/bin/curl curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@jefim jefim marked this pull request as ready for review December 2, 2025 07:25
@jefim jefim merged commit 29c744c into main Dec 2, 2025
5 checks passed
@jefim jefim deleted the copilot/fix-insert-returning-value branch December 2, 2025 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants