Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql Docker上的Postgres-超出堆栈深度限制_Postgresql_Database Trigger - Fatal编程技术网

Postgresql Docker上的Postgres-超出堆栈深度限制

Postgresql Docker上的Postgres-超出堆栈深度限制,postgresql,database-trigger,Postgresql,Database Trigger,我在本地Docker上安装了Postgres(最新版本): docker compose: version: '3.1' services: postgres: image: postgres restart: always ports: - 5435:5432 environment: POSTGRES_PASSWORD: xxxxxxx volumes: - pgdata:/var/lib/postgresql/

我在本地Docker上安装了Postgres(最新版本):

docker compose:

version: '3.1'
services:
  postgres:
    image: postgres
    restart: always
    ports:
      - 5435:5432
    environment:
      POSTGRES_PASSWORD: xxxxxxx
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    command:
      - "postgres"
      - "-c"
      - "max_stack_depth=7680"

volumes:
  pgdata:
networks:
  network1:
我的桌子:

create TABLE dictionary.language (
  id bigserial NOT NULL PRIMARY KEY,
  lang_name text NOT NULL
);

create TABLE dictionary.level (
  id bigserial NOT NULL PRIMARY KEY,
  level smallint NOT NULL
);

create TABLE dictionary.word (
  id bigserial NOT NULL PRIMARY KEY,
  name text,
  translation text,
  language_abbr_id bigint references language(id),
  level_id smallint references level(id),
  last_reviewed TIMESTAMP not null DEFAULT clock_timestamp()
);


create TABLE dictionary.examples (
   id bigserial NOT NULL PRIMARY KEY,
   sentence text NOT NULL,
   translation text NOT NULL,
   word_id bigint references word(id)
   );

create TABLE dictionary.user (
  id bigserial NOT NULL PRIMARY KEY,
  username text NOT NULL,
  password text NOT NULL
);

  CREATE OR REPLACE FUNCTION dictionary.set_last_reviewed()
  RETURNS trigger as
  $$
BEGIN
         INSERT INTO dictionary.word(last_reviewed)
         VALUES(now());

    RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';



create trigger updateLastReviewedAfterUpdate
before update on dictionary.word
for each row
execute procedure dictionary.set_last_reviewed();

create trigger updateLastReviewedAfterInsert
before insert on dictionary.word
for each row
execute procedure dictionary.set_last_reviewed();
我想在我的表中插入一些内容:

insert into word(id,name,translation,language_abbr_id,level,last_reviewed) values(1,'fabulous', 'bajeczny, fantastyczny'    ,   1   ,   6   ,   '11/09/2018 23:58'  );
然后我得到一个错误:

查询执行失败

原因:SQL错误[54001]:错误:超出堆栈深度限制提示: 增加配置参数“最大堆栈深度”(当前) 7680kB),在确保平台的堆栈深度限制足够后。 其中:SQL语句“插入到dictionary.word中(上次审查)

字典。单词(上次复习)

字典。单词(上次复习)

字典。单词(上次复习)

字典。单词(上次复习)


它可能与我的触发器有关吗?我不知道如何解决我的问题

您的插入触发器将一个新行插入表
word
,这反过来触发插入触发器,插入一个新行触发触发器……等等

据我所知,您只是试图为该列设置一个默认值

通过更改触发器处理的记录,而不是将一个全新的行插入到表中,可以实现这一点:

只需将触发器更改为:

CREATE OR REPLACE FUNCTION dictionary.set_last_reviewed()
  RETURNS trigger as
$$
BEGIN
  new.last_reviewed := now();
  RETURN NEW;
END;
$$
LANGUAGE plpgsql;
     VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement SQL statement "INSERT INTO
     VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement SQL statement "INSERT INTO
     VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement SQL statement "INSERT INTO
     VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement ...
CREATE OR REPLACE FUNCTION dictionary.set_last_reviewed()
  RETURNS trigger as
$$
BEGIN
  new.last_reviewed := now();
  RETURN NEW;
END;
$$
LANGUAGE plpgsql;