Greenplum 6.22 update table from another table

14 Views Asked by At

I am not super experienced with Postgres but I'm decent with Google. Can anyone explain to me what is wrong (and how to correct) when I attempt to update one table with another in the below self contained script illustrating the problem?

--greenplum version(): PostgreSQL 9.4.26 (Greenplum Database 6.22.0 build commit:4b6c079bc3aed35b2f161c377e208185f9310a69) on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 6.4.0, 64-bit compiled on Sep 8 2022 22:29:17

--below is a completely made up example that is self contained that illustrates my issue

DROP TABLE IF EXISTS abp;

DROP TABLE IF EXISTS bbp;

create temp TABLE abp AS

SELECT CURRENT_TIMESTAMP AS col1,CURRENT_TIMESTAMP AS col2,NULL::VARCHAR(10) AS col3

UNION ALL

SELECT CURRENT_TIMESTAMP + INTERVAL '1' day  AS col1,CURRENT_TIMESTAMP + INTERVAL '3' day  AS col2,NULL::VARCHAR(10) AS col3 DISTRIBUTED BY (col1,col2);


--SELECT * FROM a

create temp TABLE bbp AS

SELECT col1,col2,CASE WHEN col1::DATE=CURRENT_DATE::DATE THEN 'YES'::VARCHAR(10) ELSE 'NO'::VARCHAR(10) END AS col3 FROM abp ;

--SELECT * FROM abp;

--SELECT * FROM bbp;


UPDATE abp

SET abp.col3=bbp.col3

FROM bbp

WHERE abp.col1=bbp.col1; AND abp.col2=bbp.col2;

--WHY does this fail with the following error:

--ERROR: column "abp" of relation "abp" does not exist;

--how can I adjust my update one from table to another table SQL to work as expected

Expected to be able to update one table from another. Used Google to get what I believe is correct structure and syntax because how this is done is db platform dependent in my experience.

0

There are 0 best solutions below