-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert permanent table references to temp table ones #374
Comments
So far we have always followed the convention that temp tables have no schema in OhdsiSql. What would be the motivation for doing that now? It doesn't seem like something that would translate across platforms. Why do you say that Snowflake requires this? |
There is another good reason for that, the original code might have to support BOTH temporary table and normal table.
and |
I'm sorry, but that doesn't seem like a translation issue. That would change the semantics of the query. |
With current behaviour, it is quite impossible to write SQL that would work both with normal and temp tables. |
The scope of SqlRender is translation, and in translation I think we should try not to change any of the meaning. What you are proposing is using SqlRender to change the meaning of the SQL. I'm arguing that is out of scope of SqlRender. Note that in this case it is quite easy to change the meaning of the SQL the way you want: just a simple textual find-and-replace that you can do with a single line of code. I'm just saying I don't think SqlRender is a general find-and-replace tool, it is a translation tool. |
I think what you want could easily be achieved using the render(
sql = "SELECT * INTO @target_database_schema.@target_cohort_table;",
target_database_schema. = "",
target_cohort_table = "#temp_cohort"
)
# [1] "SELECT * INTO #temp_cohort;" Note the period at the end of |
Observed:
foo.#bar
is translated intofoo.bar
Expected behaviour:
foo.#bar
is translated intobar
orfoo_bar
Explanation:
According to postges documentation (see https://www.postgresql.org/docs/current/sql-createtable.html for details),
"Temporary tables exist in a special schema, so a schema name cannot be given when creating a temporary table."
Since there are some DB's that support creating temp table schema (and even kind of require that, e.g. Snowlake), untranslated sql has to contain schema specification to support these cases.
So the only logical choice for postgres translation is to drop the schema or convert it to a prefix.
The text was updated successfully, but these errors were encountered: