简体   繁体   English

postgresql:关系不存在

[英]postgresql: relation does not exist

I'm new using pl pgsql, with my pseudo code below i'm getting this error:我是使用 pl pgsql 的新手,下面的伪代码出现此错误:

relation "Client.seniority_day" does not exist关系“Client.seniority_day”不存在

How to resolve it please?请问如何解决?

code代码

DROP FUNCTION IF EXISTS table_sen_seniority;
CREATE OR REPLACE FUNCTION Client.table_sen_seniority(granularity text, OUT max_date date)
RETURNS record
LANGUAGE plpgsql
AS $function$
declare
    table_sen text := 'Client.seniority'||granularity;

 BEGIN
     execute format('SELECT MIN(dat_sub) FROM %I', table_sen) INTO subscription_from;
     execute format('SELECT FROM %I WHERE date_ >= $1', table_sen) using subscription_from;
 END;
$function$
 ;

update更新

execute format('SELECT FROM %I WHERE date_ >= $1', table_sen) using subscription_from;

You need to pass the schema and the table:您需要传递架构和表:

table_sen text := 'seniority'||granularity;

execute format('SELECT MIN(dat_sub) FROM %I.%I', 'Client', table_sen) 
  INTO subscription_from;

Note that "Client" and client would be different schema names.请注意, "Client"client将是不同的架构名称。

Your code results in您的代码导致

SELECT MIN(dat_sub) FROM "Client.seniority_day"

which treats the whole string as a table name, not a table called seniority_day in a schema called client .它将整个字符串视为表名,而不是在名为client的模式中名为seniority_day的表。

You should do it like this:你应该这样做:

DECLARE
   table_sen text := 'seniority' || granularity;
BEGIN
   EXECUTE format('SELECT MIN(dat_sub) FROM %I.%I', 'client', table_sen)
      INTO subscription_from;

That will result in这将导致

SELECT MIN(dat_sub) FROM client.seniority_day

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM