Home > Blockchain >  Postgresql , updating existing table row with another tables data
Postgresql , updating existing table row with another tables data

Time:06-22

I am trying to update a null column using another tables value but it doesn't seems to work right. below codes were tried

SET 
"Test name "= "Test"(
    SELECT Transformertest.Test,Transformertest.TestID
    FROM public.Transformertest WHERE TestID='Tes3')
WHERE test2table.Type='Oil Immersed Transformers'
UPDATE
  public.test2table
SET
  "Test name" = subquery."Test"
FROM
  (
    SELECT
      "Test"
    FROM Transformertest  WHERE "TestID"='Tes2'
  ) AS subquery
WHERE
 "Type"='Auto Transformer' AND "Phase"='3' AND "Rated Frequency"='60';

enter image description here

CodePudding user response:

  1. don't use space in column name.
  2. Integers don't need to be quoted

See the result here (enter link description here)

CodePudding user response:

what you need to do here (assuming Phase and Rated Frequency are integers) remove unnecessary "" and spaces on column names

UPDATE
  public.test2table
SET
  test_name = subquery.Test
FROM
  (
    SELECT
      test
    FROM Transformertest  WHERE Test_ID='Tes2'
  ) AS subquery
WHERE
 Type='Auto Transformer' AND Phase=3 AND Rated_Frequency=60;

this should be working now

  • Related