将值插入到 PostgreSQL 中的列中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3205468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert value into a column in PostgreSQL
提问by nix
I am trying to figure out how to insert the same value into the entire column of a table? The table already exists and I have an empty column into which I would like to insert a certain value, for example, today's date. I have only found sources explaining how to insert values into an entire row.
我想弄清楚如何将相同的值插入到表的整个列中?该表已经存在,我有一个空列,我想在其中插入某个值,例如今天的日期。我只找到了解释如何将值插入整行的来源。
回答by dweeves
UPDATE myTable SET myColumn='newValue'
newValue can also be an expression.
newValue 也可以是一个表达式。
see http://www.postgresql.org/docs/current/static/sql-update.html
见http://www.postgresql.org/docs/current/static/sql-update.html
回答by rfusca
I think we need a bit more info to understand the issue, it sounds like you just want...
我想我们需要更多信息来理解这个问题,听起来你只是想要......
INSERT INTO table_foo (my_empty_column_name) values (current_date);
If you've already got data there and you want to UPDATE that column for all rows then...
如果您已经在那里获得了数据并且想要为所有行更新该列,那么...
UPDATE table_foo SET my_empty_column_name = current_date;
回答by Fosco
I would think you're trying to UPDATE.
我认为您正在尝试更新。
UPDATE myTable set myColumn = 'WHATEVER'
回答by Curtis
Seems like you ought to be able to do something like this:
看起来你应该能够做这样的事情:
INSERT INTO films (title) VALUES
('Tampopo'),
WHERE TRUE;
(Adapted from: http://www.postgresql.org/docs/8.2/static/sql-insert.html)
(改编自:http: //www.postgresql.org/docs/8.2/static/sql-insert.html)