I have a large list of strings. I need to create a MySQL table where each string in the list is a name of a column (all columns are integers). (I m on python with sqlalchemy).
我审视了一些例子,我认为有必要在图表中明确写出每个栏目。 表2. 大型名单的实用性
Is it possible?
增 编
I have a large list of strings. I need to create a MySQL table where each string in the list is a name of a column (all columns are integers). (I m on python with sqlalchemy).
我审视了一些例子,我认为有必要在图表中明确写出每个栏目。 表2. 大型名单的实用性
Is it possible?
增 编
您可使用tuple un Packing 。
>>> column_names = [ col1 , col2 , col3 ]
>>> columns = (Column(name, Integer) for name in column_names)
>>> table = Table( table_name , metadata, *columns) # unpacks Column instances
And here s an extended example of how you could use this to programmatically create the column names from a list of strings:
>>> column_names = [ col1 , col2 , col3 ]
>>> columns = (Column(name, Integer) for name in column_names)
>>> table = Table( data , metadata, Column( id , Integer, primary_key=True), *columns)
>>> class Data(object):
...: def __init__(self, *args):
...: for name, arg in zip(column_names, args):
...: setattr(self, name, arg)
...:
...:
>>> mapper(Data, table)
<<< <Mapper at 0x1026e9910; Data>
>>> data = Data(1, 2, 3)
>>> [x for x in dir(data) if x.startswith( col )] # see if all of our columns are there
<<< [ col1 , col2 , col3 ]
>>> data.col3 # great!
<<< 3
I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...
<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...
我把我的用心从使用QQL转向MySQL。 它与凯科特合作,现在不工作,因为我已经改变,使用MySQL。 这里的错误信息是:
We have a restaurant table that has lat-long data for each row. We need to write a query that performs a search to find all restaurants within the provided radius e.g. 1 mile, 5 miles etc. We have ...
Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...
Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...
What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...
My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...