Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate all rows of a column with same value

Tags:

sql

postgresql

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.

like image 315
punkuotukas Avatar asked Oct 25 '25 18:10

punkuotukas


1 Answers

You want update;

update currency 
    set quote_asset =  'USDT';
like image 90
Gordon Linoff Avatar answered Oct 28 '25 08:10

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!