Skip to content
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

Temporary tables are created with invalid names #784

Open
lucyb opened this issue Apr 20, 2022 · 1 comment
Open

Temporary tables are created with invalid names #784

lucyb opened this issue Apr 20, 2022 · 1 comment

Comments

@lucyb
Copy link
Contributor

lucyb commented Apr 20, 2022

When constructing a study definition, creating variables with dates (e.g '2020-01-01') or snomed codes as names results in temporary table names that are invalid in t-sql.

t-sql specifies that names cannot start with a number or contain dashes, unless surrounded by square brackets.

So, this is invalid

SELECT * INTO #14336007 FROM (

But this should work (from memory/google, haven't tested)

SELECT * INTO [#14336007] FROM (

See this change and this one for context.

@evansd
Copy link
Contributor

evansd commented Apr 20, 2022

Ah yes, we've been sort of implicitly relying on Python's syntax to enforce column name rules here as column names are usually supplied as keyword arguments which will automatically prevent numeric only or dash separated names. So I think we should add some explicit validation here to enforce the same rules for dynamically constructed study defs as well.

You're quite right that there's also a quoting issue here which should be fixed (and is fixed naturally in databuilder through using SQLAlchemy). But I don't think we should be supporting using arbitrary strings as column names as I can imagine those causing unexpected problems in other contexts and — unless I'm missing something — I don't think there's really a need for them.

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

No branches or pull requests

2 participants