我使用的声明:
INSERT INTO table (addr2, addr3)
SELECT City, State
FROM table
我试图扭转,但我不知道如何。
我想找回我的数据。现在,所有列和字段均为null
。
答案 0 :(得分:0)
您说:
...基本上只是从城市和州复制所有数据,然后将数据放入addr2和addr3.fields
如果要在表的所有行中将所有现有vagrant@vagrant:/vagrant/catalog$ python application.py
database has been set up!
* Serving Flask app "application" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
Traceback (most recent call last):
File "application.py", line 60, in <module>
app.run(host='0.0.0.0', port=5000)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 943, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 988, in run_simple
run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
sys.exit(reloader.restart_with_reloader())
File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
exit_code = subprocess.call(args, env=new_environ, close_fds=False)
File "/usr/lib/python2.7/subprocess.py", line 523, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
vagrant@vagrant:/vagrant/catalog$
替换为addr2
,并将city
替换为addr3
,则需要state
,而不是{ {1}}:
UPDATE
...,其中INSERT
是表的名称。
请注意,这将替换您先前为UPDATE foo SET addr2 = city, addr3 = state;
和foo
拥有的所有值,因此请谨慎使用。如果只想替换addr2
处的addr3
和addr2
,则可以执行以下操作:
addr3
或者,也许:
NULL
或者,根据您使用的SQL引擎,也可以使用UPDATE foo SET addr2 = city WHERE addr2 IS NULL;
UPDATE foo SET addr3 = state WHERE addr3 IS NULL;
:
UPDATE foo SET addr2 = city, addr3 = state WHERE addr2 IS NULL AND addr3 IS NULL;
UPDATE foo SET addr3 = CONCAT(city, ', ', state) WHERE addr2 IS NOT NULL AND addr3 IS NULL;
因此,删除刚插入的行,然后根据需要ISNULL()
其余行。为了安全起见,您可能要先备份数据。