nix
nix

Reputation: 4781

Insert value into a column in PostgreSQL

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.

Upvotes: 7

Views: 38266

Answers (3)

dweeves
dweeves

Reputation: 5605

UPDATE myTable SET myColumn='newValue'

newValue can also be an expression.

see http://www.postgresql.org/docs/current/static/sql-update.html

Upvotes: 13

Fosco
Fosco

Reputation: 38506

I would think you're trying to UPDATE.

UPDATE myTable set myColumn = 'WHATEVER'

Upvotes: 4

rfusca
rfusca

Reputation: 7705

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;

Upvotes: 7

Related Questions