Re: Schema variables - new implementation for Postgres 15
От | Pavel Stehule |
---|---|
Тема | Re: Schema variables - new implementation for Postgres 15 |
Дата | |
Msg-id | CAFj8pRAmGr7rgWstsuX7zT0nmhD7Lwr8wfOdcYReb_44_EiSMQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Schema variables - new implementation for Postgres 15 (Erik Rijkers <er@xs4all.nl>) |
Список | pgsql-hackers |
st 24. 8. 2022 v 10:04 odesílatel Erik Rijkers <er@xs4all.nl> napsal:
Op 24-08-2022 om 08:37 schreef Pavel Stehule:
>>
>
> I fixed these.
>
> [v20220824-1-*.patch]
Hi Pavel,
I noticed just now that variable assignment (i.e., LET) unexpectedly
(for me anyway) cast the type of the input value. Surely that's wrong?
The documentation says clearly enough:
'The result must be of the same data type as the session variable.'
Example:
create variable x integer;
let x=1.5;
select x, pg_typeof(x);
x | pg_typeof
---+-----------
2 | integer
(1 row)
Is this correct?
If such casts (there are several) are intended then the text of the
documentation should be changed.
yes - the behave is designed like plpgsql assignment or SQL assignment
(2022-08-25 19:35:35) postgres=# do $$
postgres$# declare i int;
postgres$# begin
postgres$# i := 1.5;
postgres$# raise notice '%', i;
postgres$# end;
postgres$# $$;
NOTICE: 2
DO
postgres$# declare i int;
postgres$# begin
postgres$# i := 1.5;
postgres$# raise notice '%', i;
postgres$# end;
postgres$# $$;
NOTICE: 2
DO
(2022-08-25 19:38:10) postgres=# create table foo1(a int);
CREATE TABLE
(2022-08-25 19:38:13) postgres=# insert into foo1 values(1.5);
INSERT 0 1
(2022-08-25 19:38:21) postgres=# select * from foo1;
┌───┐
│ a │
╞═══╡
│ 2 │
└───┘
(1 row)
CREATE TABLE
(2022-08-25 19:38:13) postgres=# insert into foo1 values(1.5);
INSERT 0 1
(2022-08-25 19:38:21) postgres=# select * from foo1;
┌───┐
│ a │
╞═══╡
│ 2 │
└───┘
(1 row)
This sentence is not good - the value should be casteable to the target type.
Regards
Pavel
Thanks,
Erik
В списке pgsql-hackers по дате отправления: