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.
Syntax. INSERT INTO TABLE_NAME (column1, column2, column3,... columnN) VALUES (value1, value2, value3,... valueN);
INSERT INTO Syntax 1. Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)
First thing to do is specify the table name followed by the columns where you want to insert the data or rows. Secondly, you must list a comma-separated value list after the VALUES clause. The value list must be in the same order as the columns list specified after the table name.
To insert character data, you enclose it in single quotes (') for example 'PostgreSQL Tutorial' . If you omit required columns in the INSERT statement, PostgreSQL will issue an error. In case you omit an optional column, PostgreSQL will use the column default value for insert.
UPDATE myTable SET myColumn='newValue'
newValue can also be an expression.
see http://www.postgresql.org/docs/current/static/sql-update.html
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With