PostgreSQL – SQL commands
List of some useful PostgreSQL commands in SQL queries.
How to add a column in the correct place:
alter table tablename rename to oldtable;
create table tablename (column defs go here);
insert into tablename (col1, col2, col3) select col1, col2, col3 from oldtable;
How to add a column to the end:
ALTER TABLE portfolio ADD COLUMN price_diff_open_current FLOAT NULL;
Rename the table:
alter table portfolio rename column lots to quantity;
Update the entire column with one value:
UPDATE operations SET user_id = ‘1’
Rename the database:
alter database “stocks” rename to “captures”;