powered by simpleCommunicator - 2.0.53     © 2025 Programmizd 02
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Особенности null-ов для псевдотипа record
4 сообщений из 4, страница 1 из 1
Особенности null-ов для псевдотипа record
    #39626331
Dany305
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
create type foo_type as (bar text);

create or replace function get_bar() returns foo_type
as $$
begin  
  return null::foo_type;  
end $$ language plpgsql;

create or replace function get_bar2() returns foo_type
as $$
declare
  v_bar foo_type;
begin    
  v_bar := null::foo_type;
  return v_bar;
end $$ language plpgsql;

do $$ -- 1
declare 
  v_foo record;  
begin    
  v_foo := null::foo_type;

  perform v_foo is null; --ERROR:  record "v_foo" is not assigned yet
end; $$

do $$ -- 2
declare 
  v_foo record;
begin  
  v_foo := row(null)::foo_type;

  perform v_foo is null;
end; $$

do $$ -- 3
declare 
  v_foo record;
begin  
  select null into v_foo where false;  

  perform v_foo is null; 
end; $$

do $$ -- 4
declare 
  v_foo foo_type;
begin  
  v_foo := null::foo_type;

  perform v_foo is null; 
end; $$

do $$ -- 5
declare 
  v_foo record;
  v_bar foo_type;
begin  
  v_bar := null::foo_type;
  v_foo := v_bar;

  perform v_foo is null; 
end; $$

do $$ -- 6
declare 
  v_foo record;  
begin    
  v_foo := get_bar();

  perform v_foo is null; --ERROR:  record "v_foo" is not assigned yet
end; $$

do $$ -- 7
declare 
  v_foo record;  
begin    
  v_foo := get_bar2();

  perform v_foo is null; 
end; $$



7 вроде бы одинаковых вариантов, но 2 из них не работают

Как это можно объяснить?
...
Рейтинг: 0 / 0
Особенности null-ов для псевдотипа record
    #39626373
qwwq
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Dany305,

колхоз.
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
DO
$all$
declare 
	a_sql text[];
BEGIN
	create type foo_type as (bar text);

	create or replace function get_bar() returns foo_type
	as $$
	begin  
	  return (null)::foo_type;
	end $$ language plpgsql;

	create or replace function get_bar2() returns foo_type
	as $$
	declare
	  v_bar foo_type;
	begin    
	  v_bar := null::foo_type;
	  return v_bar;
	end $$ language plpgsql;

	a_sql[1]:= $$ -- 1
	declare 
	  v_foo record;  
	begin    
	  v_foo := null::foo_type;
	  perform v_foo is null;
	end; $$;

	a_sql[2]:= $$ -- 2
	declare 
	  v_foo record;
	begin  
	  v_foo := row(null)::foo_type;

	  perform v_foo is null;
	end; $$;

	a_sql[3]:= $$ -- 3
	declare 
	  v_foo record;
	begin  
	  select null into v_foo where false;  

	  perform v_foo is null; 
	end; $$;

	a_sql[4]:= $$ -- 4
	declare 
	  v_foo foo_type;
	begin  
	  v_foo := null::foo_type;

	  perform v_foo is null; 
	end; $$;

	a_sql[5]:= $$ -- 5
	declare 
	  v_foo record;
	  v_bar foo_type;
	begin  
	  v_bar := null::foo_type;
	  v_foo := v_bar;

	  perform v_foo is null; 
	end; $$;

	a_sql[6]:= $$ -- 6
	declare 
	  v_foo record;  
	begin    
	  v_foo := get_bar();
	  perform v_foo is null;
	end; $$;

	a_sql[9]:= $$ -- 6'1
	begin    
	  perform get_bar() is null; 
	end; $$;

	a_sql[10]:= $$ -- 6'2
	declare 
	  v_foo foo_type;  
	begin    
	  v_foo := get_bar();
	  perform v_foo is null;
	end; $$;

	a_sql[7]:= $$ -- 7
	declare 
	  v_foo record;  
	begin    
	  v_foo := get_bar2();

	  perform v_foo is null; 
	end; $$;

	a_sql[8]:= $$ -- 7'1
	begin    
	  perform get_bar2() is null; 
	end; $$;

	for i in 1..cardinality(a_sql) loop
		BEGIN
			EXECUTE CONCAT ('DO $$',a_sql[i],'$$;');
			RAISE NOTICE 'i %,---- %',i,'Ok!';
		EXCEPTION WHEN OTHERS THEN
			RAISE NOTICE 'i %,sql %,Errmsg %',i,a_sql[i],SQLERRM;
		
		END;
		
	end loop;

	raise 'rollback test';

END;
$all$



Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
NOTICE:  i 1,sql  -- 1
	declare 
	  v_foo record;  
	begin    
	  v_foo := null::foo_type;
	  perform v_foo is null;
	end; ,Errmsg record "v_foo" is not assigned yet
NOTICE:  i 2,---- Ok!
NOTICE:  i 3,---- Ok!
NOTICE:  i 4,---- Ok!
NOTICE:  i 5,---- Ok!
NOTICE:  i 6,sql  -- 6
	declare 
	  v_foo record;  
	begin    
	  v_foo := get_bar();
	  perform v_foo is null;
	end; ,Errmsg record "v_foo" is not assigned yet
NOTICE:  i 7,---- Ok!
NOTICE:  i 8,---- Ok!
NOTICE:  i 9,---- Ok!
NOTICE:  i 10,---- Ok!


ERROR:  rollback test
КОНТЕКСТ:  PL/pgSQL function inline_code_block line 114 at RAISE

********** Ошибка **********

ERROR: rollback test
SQL-состояние: P0001
Контекст: PL/pgSQL function inline_code_block line 114 at RAISE

...
Рейтинг: 0 / 0
Особенности null-ов для псевдотипа record
    #39626436
antonov.impulsm
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
на правах капитана очевидности -- хотелбы сказать что случаи

4 ,
6'1 ,
6'2 ,
7'1

-- не имееют ни какого отношения к record . ни косвенно. ни как :-)

# P.S.: тема не шибко активная, так что так для поддержки беседы написал :-)
...
Рейтинг: 0 / 0
Особенности null-ов для псевдотипа record
    #39626474
qwwq
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
antonov.impulsmна правах капитана очевидности -- хотелбы сказать что случаи

4 ,
6'1 ,
6'2 ,
7'1

-- не имееют ни какого отношения к record . ни косвенно. ни как :-)

# P.S.: тема не шибко активная, так что так для поддержки беседы написал :-)как бы это речек чорного ящика шагом в сторону.
вещь обычная на тесте окрестностей ономальи.

вам то давно пора исподники сишные поднять, и убедиться глазом, из каких таких соображений присвоение запаздывает.
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Особенности null-ов для псевдотипа record
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]