Skip to content

T-SQL: a CREATE FUNCTION swallows the declaration that follows it — the next CREATE VIEW is silently absent #2719

Description

@YNFM

graphify 0.9.39, Windows, Python 3.14.2, graphify . --code-only (AST only, no backend).

A CREATE FUNCTION consumes the declaration that follows it. The function itself is extracted; the next statement is not. Swapping the function for a procedure — same file, same following statement — extracts all three.

Found while isolating a separate bracket-quoting defect; this one is independent of quoting and reproduces with bare identifiers.

Repro

A — function, then view. schema.sql:

CREATE TABLE dbo.Customer (Id INT NOT NULL PRIMARY KEY);
GO
CREATE FUNCTION dbo.CustomerName (@Id INT)
RETURNS INT
AS
BEGIN
    RETURN (SELECT Id FROM dbo.Customer WHERE Id = @Id);
END
GO
CREATE VIEW dbo.CustomerList
AS
    SELECT Id FROM dbo.Customer;
GO
graphify . --code-only

Actual — 3 nodes: schema.sql, dbo.Customer, dbo.CustomerName(). No dbo.CustomerList.

B — procedure, then the same view. Replace the function with:

CREATE PROCEDURE dbo.GetCustomer @Id INT
AS
BEGIN
    SELECT Id FROM dbo.Customer WHERE Id = @Id;
END
GO

Actual — 4 nodes: schema.sql, dbo.Customer, dbo.GetCustomer(), dbo.CustomerList. The view is back.

C — the view alone, with no callable before it, also yields all three nodes. So CREATE VIEW is extracted normally; it is the preceding CREATE FUNCTION that loses it.

Notes

The practical consequence is that whether a declaration appears in the graph depends on what precedes it, which makes a node's absence hard to attribute to anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions