Skip to content

Commit f759fd0

Browse files
committed
Use a non-ambigious syntax for generating hstore SQL
hstore(ARRAY['key', 'value'], ARRAY['key2', 'value2']) Might be mistaken for another form: hstore(ARRAY['key'], ARRAY['value']) By using the following syntax, there is not ambigiuation: hstore('key', value') || hstore('key2', 'value2')
1 parent f6ef633 commit f759fd0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

psqlextra/expressions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ def as_sql(self, compiler, connection):
4646
for key, value in self.value.items():
4747
if hasattr(value, 'as_sql'):
4848
sql, params = value.as_sql(compiler, connection)
49-
result.append('ARRAY[\'%s\', %s]' % (
49+
result.append('hstore(\'%s\', %s)' % (
5050
key, sql % params))
5151
elif value is not None:
52-
result.append('ARRAY[\'%s\', \'%s\']' % ((
52+
result.append('hstore(\'%s\', \'%s\')' % ((
5353
key, value)))
5454
else:
55-
result.append('ARRAY[\'%s\', NULL]' % key)
55+
result.append('hstore(\'%s\', NULL)' % key)
5656

57-
return 'hstore(%s)' % ','.join(result), []
57+
return '%s' % ' || '.join(result), []
5858

5959

6060
class HStoreColumn(expressions.Col):

0 commit comments

Comments
 (0)