| From: | carl clemens <cclemens968(at)gmail(dot)com> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | psql variable substitution in plpgsql loop |
| Date: | 2026-06-21 17:38:25 |
| Message-ID: | CALVj=tv3UD6hVXnqdZpGQmBFk9K9pFof+H1teMn6Gw4zx8a7Eg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi,
psql fails to populate a table in variable substitution.
the variable being within a plpgsql "goto" loop looks suspicious
thank you
Linux neptune 6.1.0-42-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.159-1
(2025-12-30) x86_64 GNU/Linux
psql (PostgreSQL) 18.2
psql -d bench -v ON_ERROR_STOP=1 --variable=SCHEMANAME=test2 <
create.sql # success
create.sql
begin;
drop table if exists :SCHEMANAME.a_eod100k_s;
CREATE TABLE :SCHEMANAME.a_eod100k_s (
ts timestamp without time zone NOT NULL,
store integer NOT NULL,
dept integer NOT NULL,
category integer NOT NULL,
class integer NOT NULL,
in_stock integer
)
WITH (fillfactor='100');
ALTER TABLE ONLY :SCHEMANAME.a_eod100k_s
ADD CONSTRAINT a_eod100k_s_pk PRIMARY KEY (ts, store, dept, category,
class);
commit;
psql -d bench -v ON_ERROR_STOP=1 --variable=SCHEMANAME=test2 < aa.sql #
fail
ERROR: 42601: syntax error at or near ":"
LINE 18: insert into :SCHEMANAME.a_eod100k_s values(l_ts, s..
aa.sql:
begin;
truncate test.a_eod100k_s;
do
$$
declare
l_ts timestamp := '1970-01-01 00:00:00'::timestamp;
l_rows int4 := 10;
begin
--truncate test.a_eod100k_s;
for store in 1..16
loop
<<bstart>>
for dept in 1..32
loop
for category in 1..64
loop
for class in 1..32
loop
insert into :SCHEMANAME.a_eod100k_s values(l_ts, store, dept,
category, class, 10);
l_rows := l_rows +1;
exit bstart when l_rows > 100000;
end loop;
end loop;
end loop;
l_ts := l_ts +'1 day'::interval;
end loop;
end
$$;
commit;
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David G. Johnston | 2026-06-21 18:17:13 | Re: psql variable substitution in plpgsql loop |
| Previous Message | Laurenz Albe | 2026-06-21 05:47:33 | Re: BUG #19483: pg_upgrade fails with orphan records in pg_init_priv catalog table |