From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | nagylzs(at)gmail(dot)com |
Subject: | BUG #17272: Incorrect syntax parsed |
Date: | 2021-11-05 10:01:26 |
Message-ID: | 17272-3abe7815be15e470@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 17272
Logged by: László Nagy
Email address: nagylzs(at)gmail(dot)com
PostgreSQL version: 12.8
Operating system: Ubuntu 20.04.3 LTS on amd64
Description:
Formally, the INTO should always precede the FROM keyword in a SELECT INTO
statement. ( https://www.postgresql.org/docs/12/sql-selectinto.html )
Today we accidentally wrote this in a plpsql function:
CREATE OR REPLACE FUNCTION wf.trg_after_update_workflow_station ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $function$
DECLARE
selected_user_id float;
BEGIN
IF (NEW.station_id IS DISTINCT FROM OLD.station_id) THEN
IF (NEW.station_id = 2105) THEN
select su.id from sys.sec_user su into selected_user_id inner
join kap.training_permit tp on
su.id = tp.sec_user_id inner join wf.workflow w on w.rec_id =
tp.id where w.rec_id = NEW.rec_id;
perform from sys.sec_user_group where user_id = selected_user_id
and group_id = 35;
IF NOT FOUND THEN
INSERT INTO sys.sec_user_group (id, group_id, user_id)
VALUES (nextval('sys.id_seq'), 35, selected_user_id);
END IF;
END IF;
<more code here>
END
$function$
As you can see, we have used it in this order:
SELECT <expression> FROM tablename INTO variable INNER JOIN .....
I was very surprised that it actually worked! I think this should be a
syntax error. (Or maybe if this is not a syntax error, then it should be
documented?)
From | Date | Subject | |
---|---|---|---|
Next Message | Semab Tariq | 2021-11-05 10:21:15 | Re: CREATE INDEX CONCURRENTLY does not index prepared xact's data |
Previous Message | 菊池祐 | 2021-11-05 09:15:01 | Re: BUG #17269: Why is virtual memory usage of PostgreSQL growing constantly? |