SQL schema inference from multiple injected schema snippets.
Answered
I have some code in typescript that creates a table in one statement and then references it in another statement. The schema inference for something like this works fine if both statements were in an sql file, but if they are in two different statements where the sql language is injected, it doesn't work.
I'm wondering if there is any way this could be made to work? The example shown is typescript and snowflake, but I'm guessing this is not specific to a programming language and SQL dialect. This is also specific to the 'Database Tools and SQL' plugin.
-- test.sql
create table test_table (
name STRING
);
-- SQL language support will be aware that the 'test_table' table exists
select name from test_table;
// test.ts
dbDriver.runQuery(`
create table test_table (
name STRING
);`
)
// The injected SQL language support is not aware of 'test_table' here
dbDriver.runQuery(`select name from test_table;`)
Please sign in to leave a comment.
Looks like this case is not supported automatically out of the box. Please file a request at https://youtrack.jetbrains.com/issues/DBE with a sample code.
You can try creating a DDL data source out from the .sql/.ddl files, where you declare all the database objects, then create the IDE Data Source as the DDL data source and map this typescript file to this DDL data source in Settings (Preferences on macOS) | Languages & Frameworks | SQL Resolution Scopes settings.