Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39661
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-02-23 03:55 -0800 |
| Message-ID | <9f33141f-7cca-4f67-b030-bf16dda778fb@googlegroups.com> (permalink) |
| Subject | Escaping list of numbers for Postgres column names |
| From | andydtaylor@gmail.com |
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Escaping list of numbers for Postgres column names andydtaylor@gmail.com - 2013-02-23 03:55 -0800 Re: Escaping list of numbers for Postgres column names andydtaylor@gmail.com - 2013-02-23 10:40 -0800
csiph-web