Skip to content

Commit ab09005

Browse files
committed
Updated regex to explicitly exclude sql constants.
1 parent 18edbbd commit ab09005

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

datajoint/declare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
UUID_DATA_TYPE = 'binary(16)'
1313
MAX_TABLE_NAME_LENGTH = 64
14-
CONSTANT_LITERALS = {'CURRENT_TIMESTAMP'} # SQL literals to be used without quotes (case insensitive)
14+
CONSTANT_LITERALS = {'CURRENT_TIMESTAMP', 'NULL'} # SQL literals to be used without quotes (case insensitive)
1515
EXTERNAL_TABLE_ROOT = '~external'
1616

1717
TYPE_PATTERN = {k: re.compile(v, re.I) for k, v in dict(

datajoint/expression.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .preview import preview, repr_html
1010
from .condition import AndList, Not, \
1111
make_condition, assert_join_compatibility, extract_column_names, PromiscuousOperand
12+
from .declare import CONSTANT_LITERALS
1213

1314
logger = logging.getLogger(__name__)
1415

@@ -313,9 +314,9 @@ def proj(self, *attributes, **named_attributes):
313314
Each attribute name can only be used once.
314315
"""
315316
# new attributes in parentheses are included again with the new name without removing original
316-
duplication_pattern = re.compile(r'\s*\(\s*(?P<name>\w*[a-z]+\w*)\s*\)\s*$')
317+
duplication_pattern = re.compile(fr'^\s*\(\s*(?!{"|".join(CONSTANT_LITERALS)})(?P<name>[a-zA-Z_]+\w*)\s*\)\s*$')
317318
# attributes without parentheses renamed
318-
rename_pattern = re.compile(r'\s*(?P<name>\w*[a-z]+\w*)\s*$')
319+
rename_pattern = re.compile(fr'^\s*(?!{"|".join(CONSTANT_LITERALS)})(?P<name>[a-zA-Z_]+\w*)\s*$')
319320
replicate_map = {k: m.group('name')
320321
for k, m in ((k, duplication_pattern.match(v)) for k, v in named_attributes.items()) if m}
321322
rename_map = {k: m.group('name')

0 commit comments

Comments
 (0)