Escaping list of numbers for Postgres column names

A

andydtaylor

Hi

I have some convenient short place name IDs which would be handy for columnnames. 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:
['9400ZZLUACY1', '490000238006', '490000276005', '9400ZZLUACT2']

I'm producing it using this code:
.... if row[8]:
.... # Station values for database
.... stn_list_short.append(row[0])

And trying to employ the list something like this:


Thanks,


Andy
 
A

andydtaylor

In reply to my own question, postgres column names must begin with a letter or an underscore. So this is what I have done:
.... if row[8]:
.... stn_list_short.append("_" + row[0])

I can now use stn_list_short to create my columns
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top