-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output binding only upserting columns present in the first row #888
Comments
Could you provide the CREATE TABLE script for your DB? |
Hi Charles, The data for the function in question is all confidential, so I'm using placeholder names for columns here, and I'm only showing the first few columns of the table SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[destination_sql_table](
[pk] [char](4) NOT NULL,
[column1] [char](3) NULL,
[column2] [char](2) NULL,
[column3] [int] NULL,
) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
ALTER TABLE [dbo].[destination_sql_table] ADD CONSTRAINT [PK_destination_sql_table] PRIMARY KEY CLUSTERED
(
[pk] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO I don't think there's an issue with the database columns themselves. There have been function executions in the past that have inserted values into column3 without any issues. For those executions the first row being inserted had a value present for column3, and the SQL Audit Logs show references to it in the For some of those working executions the full column set was not present for all rows, but when it worked it was always present in the first row. |
Thanks, I just wanted to confirm that you had a nullable extra column. I can confirm that we are indeed just looking at the first row when retrieving columns to look at - you can see the relevant code here : https://github.com/Azure/azure-functions-sql-extension/blob/main/src/SqlAsyncCollector.cs#L229 It's currently expected that all items passed in are the same - and that any optional values are still defined for every row. You can accomplish this by using the
Even better would be to create a class for your object - that way you can easily guarantee all the required columns are there and that optional columns have a default value. You can see an example of this in our samples with the Let us know if this doesn't work for you and we can help try to find a better solution! |
I just sent out a PR to update the docs to hopefully make this more clear |
Thanks Charles, I've adjusted my code and this seems to be working as expected. |
I have a Python function where I want to output multiple rows that may have different sets of columns. I am using an SQL output binding, passing .set() an SqlRowList.
The function code looks like this
Running this function produces a log like the following:
The server audit log shows that the following statement was executed:
It seems to me that the output_table.set(output_rows) statement is only upserting the columns that are present in the first row. Is this the expected behaviour? Is there any way to upsert multiple rows with differing columns to a table in one function call?
I have tried to insert individual SqlRows inside a loop, but that method seems to only actually send the final call to .set() to the database.
The text was updated successfully, but these errors were encountered: