Escaping list of numbers for Postgres column names
andydtaylor at gmail.com
andydtaylor at gmail.com
Sat Feb 23 06:55:14 EST 2013
Hi
I have some convenient short place name IDs which would be handy for column names. Unfortunately, many begin with a number.
I can work around this by appending a letter to each one, but should I escape the number in such a way that I can use it directly as my column name, in the same way as I might an apostrophe? How could I do that? I wondered what the best approach is to take.
My python list come out looking like this:
>>> print stn_list_short
['9400ZZLUACY1', '490000238006', '490000276005', '9400ZZLUACT2']
I'm producing it using this code:
>>> for row in cursor_from:
... if row[8]:
... # Station values for database
... stn_list_short.append(row[0])
And trying to employ the list something like this:
>>> create_table_fields = '(id serial PRIMARY KEY, station_code varchar, %s varchar)' % ' varchar, '.join(map(str, "\" + str(stn_list_short)))
Thanks,
Andy
More information about the Python-list
mailing list