pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17272: Incorrect syntax parsed
2+ messages / 2 participants
[nested] [flat]

* BUG #17272: Incorrect syntax parsed
@ 2021-11-05 10:01  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2021-11-05 10:01 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: nagylzs@gmail.com

The following bug has been logged on the website:

Bug reference:      17272
Logged by:          László Nagy
Email address:      nagylzs@gmail.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?)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #17272: Incorrect syntax parsed
@ 2021-11-05 13:49  Tom Lane <tgl@sss.pgh.pa.us>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2021-11-05 13:49 UTC (permalink / raw)
  To: nagylzs@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> Formally, the INTO should always precede the FROM keyword in a SELECT INTO
> statement. ( https://www.postgresql.org/docs/12/sql-selectinto.html )

That is not the appropriate reference for plpgsql's version of
SELECT INTO.  You should be reading

https://www.postgresql.org/docs/12/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW

which explains plpgsql's rules for where to put INTO.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-11-05 13:49 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 10:01 BUG #17272: Incorrect syntax parsed PG Bug reporting form <noreply@postgresql.org>
2021-11-05 13:49 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox