Skip to content

Add udtf SQL prefix#459

Merged
SanjulaGanepola merged 7 commits intomainfrom
feature/udtf-sql-prefix
Jan 16, 2026
Merged

Add udtf SQL prefix#459
SanjulaGanepola merged 7 commits intomainfrom
feature/udtf-sql-prefix

Conversation

@SanjulaGanepola
Copy link
Member

@SanjulaGanepola SanjulaGanepola commented Oct 10, 2025

Changes

This PR adds udtf as a new SQL prefix for generating the skeleton for a user-defined table function as requested in #458

image

Signed-off-by: Sanjula Ganepola <Sanjula.Ganepola@ibm.com>
Signed-off-by: Sanjula Ganepola <Sanjula.Ganepola@ibm.com>
@SanjulaGanepola SanjulaGanepola requested review from a team and forstie October 10, 2025 00:16
@github-actions
Copy link

github-actions bot commented Oct 10, 2025

👋 A new build is available for this PR based on 226e6b2.

@forstie
Copy link
Collaborator

forstie commented Oct 10, 2025

I think we should add some of the most important UDTF keywords.

NOT DETERMINISTIC
NO EXTERNAL ACTION
READS SQL DATA
SET OPTION
COMMIT = *NONE ,
DYNUSRPRF = *USER ,
USRPRF = *USER

Signed-off-by: Sanjula Ganepola <Sanjula.Ganepola@ibm.com>
@SanjulaGanepola
Copy link
Member Author

I think we should add some of the most important UDTF keywords.

Done! I updated the screen cap above

@forstie
Copy link
Collaborator

forstie commented Oct 11, 2025

ON Common1, I did
udtf: select * from dogshow.account

Any and all columns returned by the udtf should be referenced by name.
Using SELECT * means that the UDTF will break when a column is added later.

`-- statement:
-- select * from dogshow.account

-- User-defined table function
CREATE OR REPLACE FUNCTION MyFunction()
RETURNS TABLE (
CLINAME VARCHAR(100)
)
NOT DETERMINISTIC
NO EXTERNAL ACTION
READS SQL DATA
SET OPTION COMMIT = *NONE,
DYNUSRPRF = *USER,
USRPRF = *USER
BEGIN
RETURN select * from dogshow.account;
END;`

@forstie
Copy link
Collaborator

forstie commented Oct 11, 2025

Delimited column names aren't handled by the support.
Example:


-- statement:
-- update: SELECT "cLo" FROM "CaMel"."CoWt"

-- User-defined table function
CREATE OR REPLACE FUNCTION MyFunction()
  RETURNS TABLE (
    cLo INTEGER
  )
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  READS SQL DATA
  SET OPTION COMMIT = *NONE,
             DYNUSRPRF = *USER,
             USRPRF = *USER
  BEGIN
    RETURN SELECT * FROM "CaMel"."CoWt";
  END;

Copy link
Contributor

@chrjorgensen chrjorgensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SanjulaGanepola See comments by @forstie for required changes.

Signed-off-by: Sanjula Ganepola <Sanjula.Ganepola@ibm.com>
@SanjulaGanepola
Copy link
Member Author

@forstie @chrjorgensen This PR is ready for review and testing again.

udtf: select * from dogshow.account
-- statement:
-- select * from dogshow.account

-- User-defined table function
CREATE OR REPLACE FUNCTION MyFunction()
  RETURNS TABLE (
    CLINAME VARCHAR(100)
  )
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  READS SQL DATA
  SET OPTION COMMIT = *NONE,
             DYNUSRPRF = *USER,
             USRPRF = *USER
  BEGIN
    RETURN select CLINAME
            from dogshow.account;
  END;
udtf: SELECT "cLo" FROM "CaMel"."CoWt"
-- statement:
-- SELECT "cLo" FROM "CaMel"."CoWt"

-- User-defined table function
CREATE OR REPLACE FUNCTION MyFunction()
  RETURNS TABLE (
    cLo INTEGER
  )
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  READS SQL DATA
  SET OPTION COMMIT = *NONE,
             DYNUSRPRF = *USER,
             USRPRF = *USER
  BEGIN
    RETURN SELECT "cLo" FROM "CaMel"."CoWt";
  END;

@forstie
Copy link
Collaborator

forstie commented Dec 4, 2025

CEAC had a good comment in general, that applies here.

We could include DBGVIEW = *SOURCE in the Set Option statement.
Or at least include it commented out?

@forstie
Copy link
Collaborator

forstie commented Dec 4, 2025

I think I have the vsix properly updated.
I am seeing...

udtf: select * from dogshow.account;

Create this, which is wrong

-- User-defined table function
CREATE OR REPLACE FUNCTION MyFunction()
RETURNS TABLE (
CLINAME VARCHAR(100)
)
NOT DETERMINISTIC
NO EXTERNAL ACTION
READS SQL DATA
SET OPTION COMMIT = *NONE,
DYNUSRPRF = *USER,
USRPRF = *USER
BEGIN
RETURN CLINAME
select * from dogshow.account;
END;

Signed-off-by: Sanjula Ganepola <Sanjula.Ganepola@ibm.com>
@SanjulaGanepola
Copy link
Member Author

@forstie
Copy link
Collaborator

forstie commented Dec 6, 2025

I did the install over again, cmd-Q to kill vs, restarted and still see this
image

@SanjulaGanepola
Copy link
Member Author

@forstie I gave this a try again and it works fine on my end. I also had Devansh try this out and it also works for him (he has a Mac). Can you give this a try once more?

@chrjorgensen Would you be able to give this a try?

@forstie
Copy link
Collaborator

forstie commented Jan 15, 2026

When I started to use a different IBM i, this feature started to work for me. :)

udtf: SELECT account_id, cast(null as clob(1k)) as col2 FROM BRANCH_OFFICE_099.TRANSACTIONS as a

Produces

image

Please have a look

Copy link
Collaborator

@forstie forstie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment with a query that doesn't generate cleanly using the new udtf: keyword.
Please take a look at it.

@SanjulaGanepola
Copy link
Member Author

@forstie Thanks for the review. I ended up fixing two issues you found:

  1. The issue you ran into here where random column names were appearing incorrectly should be addressed now
  2. The issue you ran into here should also be fixed. I added support for more built-in data types: https://github.com/codefori/vscode-db2i/pull/459/files#diff-b623628cf0577b6d13e04dd300c1256f612379dd6351e336eea9650c135f8009R107-R166. Let me know if anything is missing from this set. I got this based on https://www.ibm.com/docs/en/i/7.6.0?topic=statements-create-table

@SanjulaGanepola SanjulaGanepola mentioned this pull request Jan 16, 2026
9 tasks
@forstie
Copy link
Collaborator

forstie commented Jan 16, 2026

The improvements work very well, thank you.
Along the way, I noticed that if the query has unnamed columns, the resulting CREATE FUNCTION is syntactically invalid.
Now, of course the user of this tool should decide on a good name, so I think I'm AOK with the current behavior.
I just wanted to make sure that you knew.

udtf: select lower('HI') from sysibm.sysdummy1;

-- User-defined table function
CREATE OR REPLACE FUNCTION MyFunction()
RETURNS TABLE (
00001 VARCHAR(2)
)
NOT DETERMINISTIC
NO EXTERNAL ACTION
READS SQL DATA
SET OPTION COMMIT = *NONE,
DBGVIEW = *SOURCE,
DYNUSRPRF = *USER,
USRPRF = *USER
BEGIN
RETURN select lower('HI') from sysibm.sysdummy1;
END;

Copy link
Collaborator

@forstie forstie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice strides forward. Well done!

@SanjulaGanepola SanjulaGanepola dismissed chrjorgensen’s stale review January 16, 2026 05:09

Comments addressed. Lets merge!

@SanjulaGanepola SanjulaGanepola merged commit 278e730 into main Jan 16, 2026
1 check passed
@sebjulliand sebjulliand deleted the feature/udtf-sql-prefix branch January 16, 2026 07:52
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.

SQL prefixes add prefix to create SQL table function return list

3 participants