UPDATE from CTE syntax error

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: UPDATE from CTE syntax error
Date: 2018-05-26 16:21:12
Message-ID: CAADeyWgGcDe652eet9cTKdcycLfym8GL7u4fxQf4Ye+BzuHzdQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Good evening,

I am struggling with the syntax, please help.

This query with a CTE works ok:

WITH

extract_letters AS (

SELECT

mid,

STRING_AGG(x->>'letter', '') AS
letters
FROM (

SELECT

mid,

JSONB_ARRAY_ELEMENTS(tiles) AS x

FROM words_moves

WHERE action='play'

) z
GROUP BY mid)

SELECT * from extract_letters;

mid | letters
--------+---------
12 | АКЖОЛ
15 | ДМО
16 | ТО
20 | ШГА
21 | КТИ
22 | ВОЗ
24 | АКПОНК

But UPDATEing from the CTE does not -

WITH extract_letters AS (

SELECT

mid,

STRING_AGG(x->>'letter', '') AS letters

FROM (

SELECT

mid,

JSONB_ARRAY_ELEMENTS(tiles) AS x

FROM words_moves

WHERE action='play'

) z

GROUP BY mid)
UPDATE words_moves m

SET m.letters =
el.letters
FROM
extract_letters el
WHERE
m.mid = el.mid;

ERROR: 42703: column "m" of relation "words_moves" does not exist
LINE 14: SET m.letters = el.letters
^

Regards
Alex

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2018-05-26 16:22:00 Re: UPDATE from CTE syntax error
Previous Message Olivier Gautherot 2018-05-26 13:23:02 Re: Fast logical replication jump start with PG 10