powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / как обновить тип?
21 сообщений из 21, страница 1 из 1
как обновить тип?
    #37927776
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Всем привет!

В хранимке использую return setof Таблица. Изменил колонки таблиц + добавил новые. Теперь хранимка не работает (((. Не видит некоторые поля, а при удалении добавленных, пишет, что их по-прежнему 20...
Можно ли запросом обновить состояние типа Taблица?

Спасибо!
...
Рейтинг: 0 / 0
как обновить тип?
    #37927851
V&N
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
V&N
Гость
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
postgres=# drop table if exists xx cascade;
NOTICE:  table "xx" does not exist, skipping
DROP TABLE
postgres=# create table xx (id int);
CREATE TABLE
postgres=# create or replace function get_xx() returns setof xx as $$begin return; end;$$ language plpgsql;
CREATE FUNCTION
postgres=# select * from get_xx();
  id 
----
(0 строк)

postgres=#  alter table xx add column v varchar(10); 
ALTER TABLE
postgres=# select * from get_xx();
  id | v 
----+---
(0 строк)
WAIDW?
...
Рейтинг: 0 / 0
как обновить тип?
    #37927885
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
V&N
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
postgres=# drop table if exists xx cascade;
NOTICE:  table "xx" does not exist, skipping
DROP TABLE
postgres=# create table xx (id int);
CREATE TABLE
postgres=# create or replace function get_xx() returns setof xx as $$begin return; end;$$ language plpgsql;
CREATE FUNCTION
postgres=# select * from get_xx();
  id 
----
(0 строк)

postgres=#  alter table xx add column v varchar(10); 
ALTER TABLE
postgres=# select * from get_xx();
  id | v 
----+---
(0 строк)
WAIDW?

Вот если снова удалить xx и выполнить select * from get_xx(); выдает сообщение о том, что параметров должно быть 2 (хотя уже 1), даже после replace function get_xx().
...
Рейтинг: 0 / 0
как обновить тип?
    #37927897
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
IRONMAN удалить xx . Опечатался, удалить поле v.
...
Рейтинг: 0 / 0
как обновить тип?
    #37927901
Фотография Maxim Boguk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
IRONMANV&N
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
postgres=# drop table if exists xx cascade;
NOTICE:  table "xx" does not exist, skipping
DROP TABLE
postgres=# create table xx (id int);
CREATE TABLE
postgres=# create or replace function get_xx() returns setof xx as $$begin return; end;$$ language plpgsql;
CREATE FUNCTION
postgres=# select * from get_xx();
  id 
----
(0 строк)

postgres=#  alter table xx add column v varchar(10); 
ALTER TABLE
postgres=# select * from get_xx();
  id | v 
----+---
(0 строк)
WAIDW?

Вот если снова удалить xx и выполнить select * from get_xx(); выдает сообщение о том, что параметров должно быть 2 (хотя уже 1), даже после replace function get_xx().

переконнектится надо... чтобы она процедуру перекомпиляла...
если не поможет - напишите подумаю в чем беда
...
Рейтинг: 0 / 0
как обновить тип?
    #37927930
V&N
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
V&N
Гость
IRONMAN, ничего у меня на получается
Код: plaintext
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.
postgres=# create table xx (id int);
CREATE TABLE
postgres=#
postgres=# create or replace function get_xx1() returns setof xx as $$begin return; end;$$ language plpgsql;
CREATE FUNCTION
postgres=# create or replace function get_xx2() returns setof xx as $$select * from xx$$ language sql;
CREATE FUNCTION
postgres=# select * from get_xx1();
 id
----
(0 строк)

postgres=# select * from get_xx2();
 id
----
(0 строк)

postgres=# alter table xx add column v varchar(10);
ALTER TABLE
postgres=# select * from get_xx1();
 id | v
----+---
(0 строк)

postgres=# select * from get_xx2();
 id | v
----+---
(0 строк)

postgres=# alter table xx drop column v;
ALTER TABLE
postgres=# select * from get_xx1();
 id
----
(0 строк)

postgres=# select * from get_xx2();
 id
----
(0 строк)
какая версия postgresql?
...
Рейтинг: 0 / 0
как обновить тип?
    #37927945
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Maxim Boguk
если не поможет - напишите подумаю в чем беда

переподключение не помогает...
...
Рейтинг: 0 / 0
как обновить тип?
    #37927949
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
V&N какая версия postgresql?
8.4
...
Рейтинг: 0 / 0
как обновить тип?
    #37927960
V&N
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
V&N
Гость
IRONMAN , приведенный тест выполнялся на 8.4 (PostgreSQL 8.4.12 on x86_64-unknown-linux-gnu, compiled by GCC gcc (SUSE Linux) 4.6.2, 64-bit).
Так что, ...
...
Рейтинг: 0 / 0
как обновить тип?
    #37927963
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот подробная ошибка при выполнении функции:

ERROR: structure of query does not match function result type
DETAIL: Number of returned columns (17) does not match expected column count (20).
CONTEXT: PL/pgSQL function "GetAll" line 2 at RETURN QUERY
...
Рейтинг: 0 / 0
как обновить тип?
    #37927992
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
V&N IRONMAN , приведенный тест выполнялся на 8.4 (PostgreSQL 8.4.12 on x86_64-unknown-linux-gnu, compiled by GCC gcc (SUSE Linux) 4.6.2, 64-bit).
Так что, ...

Попробуйте плз так:
returns setof xx as $$begin return query select * from xx; end;$$ language plpgsql;
...
Рейтинг: 0 / 0
как обновить тип?
    #37928000
V&N
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
V&N
Гость
IRONMAN, такие ошибки не от удаления/добавления столбцов, а из за
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
postgres=# drop table if exists xx cascade;
NOTICE:  drop cascades to function get_xx2()
DROP TABLE
postgres=# create table xx (id int);
CREATE TABLE
postgres=# create or replace function get_xx2() returns setof xx as $$ select id from xx $$ language sql;
CREATE FUNCTION
postgres=#
postgres=# select * from get_xx2();
 id
----
(0 строк)

postgres=# alter table xx add column v varchar(10);
ALTER TABLE
postgres=# select * from get_xx2();
ERROR:  return type mismatch in function declared to return xx
ПОДРОБНО:  Final statement returns too few columns.
КОНТЕКСТ:  SQL function "get_xx2" during startup
вместе со структурой - меняйте тело функции, или используйте plpgsql+declare myVar myTable; myVar.... := ... .
...
Рейтинг: 0 / 0
как обновить тип?
    #37928020
V&N
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
V&N
Гость
IRONMANПопробуйте плз так:
returns setof xx as $$begin return query select * from xx; end;$$ language plpgsql;не буду, знаю что будет работать без ошибок, проверьте сами. ;)
...
Рейтинг: 0 / 0
как обновить тип?
    #37928030
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
V&N IRONMAN, такие ошибки не от удаления/добавления столбцов, а из за
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
postgres=# drop table if exists xx cascade;
NOTICE:  drop cascades to function get_xx2()
DROP TABLE
postgres=# create table xx (id int);
CREATE TABLE
postgres=# create or replace function get_xx2() returns setof xx as $$ select id from xx $$ language sql;
CREATE FUNCTION
postgres=#
postgres=# select * from get_xx2();
 id
----
(0 строк)

postgres=# alter table xx add column v varchar(10);
ALTER TABLE
postgres=# select * from get_xx2();
ERROR:  return type mismatch in function declared to return xx
ПОДРОБНО:  Final statement returns too few columns.
КОНТЕКСТ:  SQL function "get_xx2" during startup
вместе со структурой - меняйте тело функции, или используйте plpgsql+declare myVar myTable; myVar.... := ... .

Вот функция:

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
CREATE OR REPLACE FUNCTION "GetAll"()
RETURNS SETOF "Table1" AS
$BODY$
BEGIN
	return query
         select  * from "Table1";
END
$BODY$
  LANGUAGE plpgsql VOLATILE SECURITY DEFINER
  COST 100
  ROWS 1000;
ALTER FUNCTION "GetAll"()
  OWNER TO postgres;



Менял и тело на select fielld1,..........................
Может не так меняю?
Напишите плз. другой рабочий вариант данной функции. очень надо ((
...
Рейтинг: 0 / 0
как обновить тип?
    #37928127
V&N
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
V&N
Гость
IRONMAN,
Код: 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.
drop table if exists xx cascade;
create table xx (id int);


create or replace function get_xx1() returns setof xx as 
$$
declare
  result xx;
  r record;
begin 
  for r in (select id from xx)
  loop
     result.id = r.id;
    return next result;
  end loop;

end;
$$language plpgsql;
create or replace function get_xx2() returns setof xx as $$begin return query select * from xx;end;$$language plpgsql;
select * from get_xx1() ;
select * from get_xx2() ;
insert into xx (id ) values (1),(2);
select * from get_xx1() ;
select * from get_xx2() ;
alter table xx add column v varchar(10);
select * from get_xx2() ;
--а вот для get_xx1, нужно переподключение или пересоздать функцию, иначе ERROR: wrong record type supplied in...
select * from get_xx1() ;

Код: plaintext
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.
postgres=# drop table if exists xx cascade;
  for r in (select id from xx)
NOTICE:  drop cascades to 2 other objects
ПОДРОБНО:  drop cascades to function get_xx1()
drop cascades to function get_xx2()
  loop
     result.id = r.id;
    return next result;
  end loop;

end;
$$language plpgsql;
create or replace function get_xx2() returns setof xx as $$begin return query select * from xx;end;$$language plpgsql;
select * from get_xx1() ;
select * from get_xx2() ;
insert into xx (id ) values (1),(2);
select * from get_xx1() ;
select * from get_xx2() ;
alter table xx add column v varchar(10);
select * from get_xx2() ;
--а вот для get_xx1, нужно переподключение или пересоздать функцию, иначе ERROR: wrong record type supplied in
select * from get_xx1() ;
DROP TABLE
postgres=# create table xx (id int);
CREATE TABLE
postgres=#
postgres=#
postgres=# create or replace function get_xx1() returns setof xx as
postgres-# $$
postgres$# declare
postgres$#   result xx;
postgres$#   r record;
postgres$# begin
postgres$#   for r in (select id from xx)
postgres$#   loop
postgres$#      result.id = r.id;
postgres$#     return next result;
postgres$#   end loop;
postgres$#
postgres$# end;
postgres$# $$language plpgsql;
CREATE FUNCTION
postgres=#  create or replace function get_xx2() returns setof xx as $$begin return query select * from xx;end;$$language plpgsql; 
CREATE FUNCTION
postgres=# select * from get_xx1() ;
 id
----
(0 строк)

postgres=# select * from get_xx2() ;
 id
----
(0 строк)

postgres=# insert into xx (id ) values (1),(2);
INSERT 0 2
postgres=# select * from get_xx1() ;
 id
----
  1
  2
(2 строки)

postgres=# select * from get_xx2() ;
 id
----
  1
  2
(2 строки)

postgres=# alter table xx add column v varchar(10);
ALTER TABLE
postgres=# select * from  get_xx2 () ;
 id | v
----+---
  1 |
  2 |
(2 строки)

postgres=# --а вот для  get_xx1 , нужно переподключение или пересоздать функцию, иначе ERROR: wrong record type supplied in...
postgres=# select * from  get_xx1 () ;
ERROR:  wrong record type supplied in RETURN NEXT
КОНТЕКСТ:  PL/pgSQL function "get_xx1" line 8 at RETURN NEXT
...
Рейтинг: 0 / 0
как обновить тип?
    #37928197
V&N
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
V&N
Гость
p.s.
если сделать такой финт ушами
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
create or replace function get_xx1() returns setof xx as 
$$
declare
  --result xx;
  result record;
  r record;
begin
  select xx.*  
    into result
    from xx    
   where false;
  for r in (select id from xx)
  loop
     result.id = r.id;
      return next result;
  end loop;

end;
$$language plpgsql;

пересоздание/переподключение не понадобится
...
Рейтинг: 0 / 0
как обновить тип?
    #37928274
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
V&Np.s.
если сделать такой финт ушами
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
create or replace function get_xx1() returns setof xx as 
$$
declare
  --result xx;
  result record;
  r record;
begin
  select xx.*  
    into result
    from xx    
   where false;
  for r in (select id from xx)
  loop
     result.id = r.id;
      return next result;
  end loop;

end;
$$language plpgsql;

пересоздание/переподключение не понадобится

Попробовал и так - ошибка та же...
...
Рейтинг: 0 / 0
как обновить тип?
    #37928293
V&N
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
V&N
Гость
IRONMAN, пример те что я дал вызывают ошибку? Не верю.
Давайте свой код.
...
Рейтинг: 0 / 0
как обновить тип?
    #37928294
IRONMAN
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
авторp.s.
если сделать такой финт ушами

Ваш то пример с таблицей хх работает, а вот
с моей таблицей Table1 что-то не так.... Ее реально приплющило.
Придется только пересоздавать таблицу (и то не факт что все гуд будет). Всем спасибо.
...
Рейтинг: 0 / 0
как обновить тип?
    #37928677
Фотография Ёш
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
IRONMAN, какая у Вас версия сервера? Когда-то давно была ошибка с обработкой удалённых колонок в RETURN QUERY.
...
Рейтинг: 0 / 0
Период между сообщениями больше года.
как обновить тип?
    #38812994
Лопата
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
приподниму
Postgresql 9.3.
воспроизвели случайно

ERROR: returned record type does not match expected record type
DETAIL: Number of returned columns (6) does not match expected column count (7).

-- выскочило после ALTER TYPE для INOUT параметра //в других сеансах

после принудительного CREATE OR REPLACE -- дуло исчезло.

// забавно.
...
Рейтинг: 0 / 0
21 сообщений из 21, страница 1 из 1
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / как обновить тип?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


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