Skip to content
Advertisement

Populate all rows of a column with same value

The issue is that I have a PostgreSQL table ‘currency’ with 4 columns: ‘id’, ‘symbol’, ‘name’, ‘quote_asset’. The table contains 225 rows and column ‘quote_asset’ has all the values set to ‘null’ for now (it wasn’t populated). Now I need to populate all the rows with the same value ‘USDT’. I tried the following query:

INSERT INTO currency (quote_asset) VALUES ('USDT');

It throws the following error:

ERROR: null value in column “symbol” violates not-null constraint DETAIL: Failing row contains (227, null, null, USDT). SQL state: 23502

I’m really not an expert of SQL, so, maybe someone could suggest a query that would work fine? I believe, it shouldn’t be very difficult, but this basic thing that I was able to come up with didn’t work for me.

Advertisement

Answer

You want update;

update currency 
    set quote_asset =  'USDT';
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement