babelfish_extensions icon indicating copy to clipboard operation
babelfish_extensions copied to clipboard

[Bug]: Queries in `tempdb.sys.tables` returns no results

Open PauloHMattos opened this issue 1 year ago • 5 comments

What happened?

Queries in tempdb.sys.tables returns no results.

Running this in SSMS the return is a empty dataset

CREATE TABLE #MyTempTable (Id INT)
SELECT * FROM tempdb.sys.tables

tempdb.sys.objects also returns empty.

Version

BABEL_4_X_DEV (Default)

Extension

babelfishpg_tsql (Default)

Which flavor of Linux are you using when you see the bug?

Ubuntu (Default)

Relevant log output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct.

PauloHMattos avatar Nov 11 '24 18:11 PauloHMattos

FYI, this issue has been fixed: https://github.com/babelfish-for-postgresql/babelfish_extensions/pull/2679

shalinilohia50 avatar Mar 16 '25 19:03 shalinilohia50

Does not look like this is fixed, https://github.com/babelfish-for-postgresql/babelfish_extensions/pull/2679 fixed a different issue

1> CREATE TABLE #t (id INT)
2> GO
1> SELECT name FROM tempdb.sys.tables WHERE name like '#t%'
2> GO
name                                                                                                                            
--------------------------------------------------------------------------------------------------------------------------------

(0 rows affected)

1> SELECT name FROM sys.tables WHERE name like '#t%'
2> GO
name                                                                                                                            
--------------------------------------------------------------------------------------------------------------------------------

(0 rows affected)

tanscorpio7 avatar Mar 17 '25 00:03 tanscorpio7

While using Babelfish we can use query "SELECT RELNAME FROM sys.babelfish_get_enr_list() WHERE RELNAME LIKE '#%' to get the session local temp table names.

priyansx avatar Aug 26 '25 00:08 priyansx

While using Babelfish we can use query "SELECT RELNAME FROM sys.babelfish_get_enr_list() WHERE RELNAME LIKE '#%' to get the session local temp table names.

My application performs introspection in the regular and temp tables to extract columns, indexes and constraints. We need a way to do this in babelfish.

PauloHMattos avatar Sep 02 '25 18:09 PauloHMattos

Metadata for #tmp table columns is not currently in the Babelfish catalogs. Only object name can be obtained as shown above. There is a trick to get the metadata anyway: copy the temp table into a permanent table - then you can obtain the metadata from the regular catalogs (at least for the columns). When doing this you should make sure the table being created has a unique name. See this example: https://github.com/babelfish-for-postgresql/babelfish_extensions/blob/2da1db5aa02928e770e1bd21dc9ea9897912a1d4/contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql#L3330

robverschoor avatar Sep 02 '25 18:09 robverschoor