microsoft / DacFx

DacFx, SqlPackage, and other SQL development libraries enable declarative database development and database portability across SQL versions and environments. Share feedback here on dacpacs, bacpacs, and SQL projects.
https://aka.ms/sqlpackage-ref
MIT License
365 stars 21 forks source link

DW - support for table-valued functions missing #390

Open jasonhorner opened 10 months ago

jasonhorner commented 10 months ago

Steps to Reproduce: Create a new database project in ADS that targets synapse azure sql dedicated pool project

  1. Create a Table
    CREATE TABLE [dbo].[DimTest]
    (
    [Id] INT 
    )
    (
    DISTRIBUTION = ROUND_ROBIN,
    HEAP
    )
  2. Create and inline TVF that accesses the table:
    CREATE FUNCTION [dbo].[fnTest] (@Id bigint) 
    RETURNS TABLE
    AS
    RETURN (
    SELECT Id FROM [dbo].[DimTest]
    WHERE Id = @Id
    )

This will work if you run within SSMS,

However if put in as objects in a database project (SSDT or ADS) it will cause the build error: Build error SQL71636: You cannot use types or statements that modify the database state.

see here for more context: https://learn.microsoft.com/en-us/answers/questions/419193/azure-data-warehouse-function-has-problem-when-we

Did this occur in prior versions? If not - which version(s) did it work in?

(DacFx/SqlPackage/SSMS/Azure Data Studio)

jasonhorner commented 10 months ago

as a side note if the function doesn't reference a table or view directly the project will build successfully for example

CREATE FUNCTION [dbo].[fnTest] (@Id bigint) 
RETURNS TABLE
AS
RETURN (
SELECT @Id As Id
)
keen85 commented 8 months ago

same problem 😒