Skip to content

Instantly share code, notes, and snippets.

@jiaaro jiaaro/
Last active Aug 29, 2015

What would you like to do?
create hstore col
from django.db import connection
def hs_str(s):
s = unicode(s)
return s.replace('"', r'\"')
def dict_to_hstore(d):
hs_data = [u'"{0}" => "{1}"'.format(hs_str(k), hs_str(v)) for (k, v) in data.items()]
hs_data = u",".join(hs_data)
return "u'{0}'::hstore".format(hs_data)
cursor = connection.cursor()
i = 0
while True:
pids = list(Participant.objects.values_list('id', flat=True)[i:i+1000])
if not pids:
query = u""
for pid, data in Participant.objects.get_answer_data(pids):
if not data:
query += u"UPDATE stitcher_participant SET hs_data = %s;" % dict_to_hstore(data)
i += 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.