procedure string constant is parsed at procedure create time. - Mailing list pgsql-general

From jian he
Subject procedure string constant is parsed at procedure create time.
Date
Msg-id CACJufxGQcEnMCT7yR8+FV4cd996UwGabYtxwqi7pNzq7tf8ZtQ@mail.gmail.com
Whole thread Raw
Responses Re: procedure string constant is parsed at procedure create time.  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Re: procedure string constant is parsed at procedure create time.  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
hi.
table "test" does not exist.

---1.this will work.
CREATE or replace PROCEDURE template_create() LANGUAGE SQL
AS $proc$ DROP TABLE if exists test cascade; CREATE TABLE test(id
int4range,valid_at tsrange,name text);$proc$;

----2.this will have errors.
CREATE or replace PROCEDURE template_create() LANGUAGE SQL AS $proc$
    DROP TABLE if exists test cascade;
    CREATE TABLE test(id int4range,valid_at tsrange,name text);
    INSERT INTO test VALUES (NULL, tsrange('2018-01-01',
'2019-01-01'), 'null key');
$proc$;

----3.language plpgsql works fine.
CREATE or replace PROCEDURE template_create()
LANGUAGE plpgsql AS $proc$
    begin
        DROP TABLE if exists test101 cascade;
        CREATE TABLE test101(id int4range,valid_at tsrange,name text);
        INSERT INTO test101 VALUES (NULL, tsrange('2018-01-01',
'2019-01-01'), 'null key');
    end
$proc$;

per manual: https://www.postgresql.org/docs/current/sql-createprocedure.html
"....This form only works for LANGUAGE SQL, the string constant form
works for all languages. This form is parsed at procedure definition
time, the string constant form is parsed at execution time...."

Why does the 2nd query fail? What am I missing?



pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Postgres Out Of Memory Crash
Next
From: Alvaro Herrera
Date:
Subject: Re: procedure string constant is parsed at procedure create time.