Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPDAt-0002Xr-BC for pgsql-general@arkaria.postgresql.org; Thu, 16 Apr 2020 22:40:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jPDAq-0007v7-Ll for pgsql-general@arkaria.postgresql.org; Thu, 16 Apr 2020 22:39:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPDAq-0007v0-0t for pgsql-general@lists.postgresql.org; Thu, 16 Apr 2020 22:39:56 +0000 Received: from sonic302-22.consmr.mail.ne1.yahoo.com ([66.163.186.148]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jPDAl-0002cU-U8 for pgsql-general@postgresql.org; Thu, 16 Apr 2020 22:39:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1587076788; bh=Vw0oXhF50Vl7j2LLdXh1aQHRC5+XnekvifkANd9JABs=; h=Date:From:Reply-To:To:Subject:References:From:Subject; b=epht1/F/gMO9Z79nzixLOHHOupe6RKaCno8SsefSDWiil8dq+ucfsNqNuVN1tuAMkHA87aogEIlkGi+XrHFSkHjnRXsaJuu8u5U2hUYukEEHfB/SkqBU9XOA8Y9wVSRR5iKVLMkxdy81Ieis1GVsNDkloMfJgakesMDR+/jnqh1cj2ySBa7W4a223uAU+rItAlpCKar691r12niKe2aTzVpfQdg7jMSIV23RLNHG3xgusBr/TceU+iRYZXtj82OE8uOMGhOzdmmGL//7Y1ihMDhCqho/J/nm/TJXtBd1WJiX4S7AjoPMkxrErVWyk1TX/WBoShE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w9NNSUgp Fww7rbFbs.cUMJkX_0f7Glm45cynxc2hDKRMWPaM3JV3NKcVwRJLRS5g5J6H4vrvoqDTAwbps0ex qhBAku7zJaMZnhDu.TLdVtHM4ttx6C5JQda.O.lVhPKaCyWllzPI_R5w_cogrMFk_TyXosM5b5Ec mGnCW0.BQc70B5le.g8RoZ57ao6j4RIquXRaaJfTLSo2E.ni2D3hS6NJk0hd2.oWskzGmXSFhwei PlRwA3HHc2b1vfCNMYMjeCT5nisFQWI7yyU_r4arfoZ83avpxRO4L1sVpfQhjGehWTvLA9_T.5Es 9hVsXiM1ukO5RJaKRYmaR4Q-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Thu, 16 Apr 2020 22:39:48 +0000 Date: Thu, 16 Apr 2020 22:39:48 +0000 (UTC) From: Virendra Kumar Reply-To: Virendra Kumar To: Pgsql-general General Message-ID: <642480622.1859025.1587076788135@mail.yahoo.com> Subject: File Foreign Table Doesn't Exist when in Exception MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1859024_69119251.1587076788133" References: <642480622.1859025.1587076788135.ref@mail.yahoo.com> X-Mailer: WebService/1.1.15651 YMailNorrin Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0 Content-Length: 13902 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_1859024_69119251.1587076788133 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello Everyone, I have a weird situation with file_fdw extension when I am creating a forei= gn table in anonymous block. Here is setup: Create extension and server:=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D postgres=3D# create extension file_fdw; CREATE EXTENSION postgres=3D# CREATE SERVER log_server FOREIGN DATA WRAPPER file_fdw; CREATE SERVER Here is anonymous block, when I query the foreign table (FT) created in blo= ck with incorrect data. I get error and the FT is lost. See below:=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D postgres=3D# DO $$ postgres$# DECLARE postgres$# v_ft_file_name text; postgres$# temp_variable text; postgres$# v_sql text; postgres$# log_min_time date; postgres$# BEGIN postgres$#=20 postgres$# v_ft_file_name:=3D'abc.csv'; postgres$#=20 postgres$# v_sql:=3D 'CREATE FOREIGN TABLE "'||v_ft_file_name||'"( postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 user_name=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 text, postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 database_name=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 text, postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 connection_from=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 te= xt postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ) SERVER log_server postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 OPTIONS (filename ''/opt/postgres/122/dat= a/'||v_ft_file_name||''')'; postgres$# execute v_sql; postgres$# v_sql:=3D'select min(user_name) from "'||v_ft_file_name||'"'; postgres$# execute v_sql into log_min_time; <-- Querying from FT with incor= rect data postgres$#=C2=A0=C2=A0 =C2=A0 postgres$# END; postgres$# $$ LANGUAGE 'plpgsql'; ERROR:=C2=A0 missing data for column "database_name" CONTEXT:=C2=A0 COPY abc.csv, line 1: "aa,bb,cc" SQL statement "select min(user_name) from "abc.csv"" PL/pgSQL function inline_code_block line 19 at EXECUTE postgres=3D# postgres=3D# select ftrelid::regclass::text from pg_foreign_ta= ble=20 postgres-# where ftrelid::regclass::text like '%abc.csv%'; =C2=A0ftrelid=20 --------- (0 rows) When I don't query the FT I can see the foreign table:=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D postgres=3D# DO $$postgres$# DECLARE postgres$# v_ft_file_name text; postgres$# temp_variable text; postgres$# v_sql text; postgres$# log_min_time date; postgres$# BEGIN postgres$#=20 postgres$# v_ft_file_name:=3D'abc.csv'; postgres$#=20 postgres$# v_sql:=3D 'CREATE FOREIGN TABLE "'||v_ft_file_name||'"( postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 user_name=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 text, postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 database_name=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 text, postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 connection_from=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 te= xt postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ) SERVER log_server postgres$#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 OPTIONS (filename ''/opt/postgres/122/dat= a/'||v_ft_file_name||''')'; postgres$# execute v_sql; postgres$#=20 postgres$# v_sql:=3D'select min(user_name) from "'||v_ft_file_name||'"'; postgres$# --execute v_sql into log_min_time; <-Commented SELECT on FT postgres$#=C2=A0=C2=A0 =C2=A0 postgres$# END; postgres$# $$ LANGUAGE 'plpgsql'; DO postgres=3D#=20 postgres=3D#=20 postgres=3D# select ftrelid::regclass::text from pg_foreign_table=20 postgres-# where ftrelid::regclass::text like '%abc.csv%'; =C2=A0 ftrelid =C2=A0 ----------- =C2=A0"abc.csv" (1 row) postgres=3D#=20 When I query the table outside anonymous block it is still there. So I am t= hinking may be I am missing some concept here or hitting a bug:=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D postgres=3D# select min(user_name) from "abc.csv"; ERROR:=C2=A0 missing data for column "database_name" CONTEXT:=C2=A0 COPY abc.csv, line 1: "aa,bb,cc" postgres=3D#=20 postgres=3D#=20 postgres=3D# select ftrelid::regclass::text from pg_foreign_table=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 where ftrelid::regclass::text like '%abc.csv%'; =C2=A0 ftrelid =C2=A0 ----------- =C2=A0"abc.csv" (1 row) Regards, Virendra Kumar ------=_Part_1859024_69119251.1587076788133 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello Everyone,

I have a weird situation with file_fdw extension when I am creating a= foreign table in anonymous block. Here is setup:

Create = extension and server:
=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
postgres=3D# create extension file_fdw;=
CREATE EXTENSION
postgres=3D# CREATE SERVER log_server FOREIGN DATA = WRAPPER file_fdw;
CREATE SERVER


Here is anonymous block, when I query the foreign table (FT) cre= ated in block with incorrect data. I get error and the FT is lost. See belo= w:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D
postgres=3D# DO $$
postgres$# DECLARE
postgres$# v= _ft_file_name text;
postgres$# temp_variable text;
postgres$# v_sql t= ext;
postgres$# log_min_time date;
postgres$# BEGIN
postgres$# postgres$# v_ft_file_name:=3D'abc.csv';
postgres$#
postgres$# v_sql= :=3D 'CREATE FOREIGN TABLE "'||v_ft_file_name||'"(
postgres$#  = ;            &n= bsp;    user_name       &= nbsp;           &nbs= p; text,
postgres$#         = ;          database_name =             &nb= sp;   text,
postgres$#      &nbs= p;            connec= tion_from           =     text
postgres$#      &n= bsp;          ) SERVER log_ser= ver
postgres$#         &nbs= p;       OPTIONS (filename ''/opt/postgres/12= 2/data/'||v_ft_file_name||''')';
postgres$# execute v_sql;
postgres$#= v_sql:=3D'select min(user_name) from "'||v_ft_file_name||'"';
postgres$= # execute v_sql into log_min_time; <-- Querying from FT with incorrect d= ata
postgres$#    
postgres$# END;
postgres$# $$ LA= NGUAGE 'plpgsql';
ERROR:  missing data for column "database_name"CONTEXT:  COPY abc.csv, line 1: "aa,bb,cc"
SQL statement "select = min(user_name) from "abc.csv""
PL/pgSQL function inline_code_block line = 19 at EXECUTE

postgres=3D#
postgres=3D# sele= ct ftrelid::regclass::text from pg_foreign_table
postgres-# where ftrel= id::regclass::text like '%abc.csv%';
 ftrelid
---------
(0 r= ows)


When I do= n't query the FT I can see the foreign table:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D
postgres=3D# DO $$
postgres$# DECLARE
postgres$# = v_ft_file_name text;
postgres$# temp_variable text;
postgres$# v_sql = text;
postgres$# log_min_time date;
postgres$# BEGIN
postgres$# postgres$# v_ft_file_name:=3D'abc.csv';
postgres$#
postgres$# v_sq= l:=3D 'CREATE FOREIGN TABLE "'||v_ft_file_name||'"(
postgres$# &nbs= p;            &= nbsp;    user_name       =             &nb= sp; text,
postgres$#        &nbs= p;          database_name = ;            &n= bsp;   text,
postgres$#      &nb= sp;            conne= ction_from           = ;    text
postgres$#      &= nbsp;          ) SERVER log_se= rver
postgres$#         &nb= sp;       OPTIONS (filename ''/opt/postgres/1= 22/data/'||v_ft_file_name||''')';
postgres$# execute v_sql;
postgres$= #
postgres$# v_sql:=3D'select min(user_name) from "'||v_ft_file_name||'= "';
postgres$# --execute v_sql into log_min_time; <-Commented SELECT = on FT
postgres$#    
postgres$# END;
postgres$# $$ = LANGUAGE 'plpgsql';
DO
postgres=3D#
postgres=3D#
postgres=3D#= select ftrelid::regclass::text from pg_foreign_table
postgres-# where = ftrelid::regclass::text like '%abc.csv%';
  ftrelid  
-----= ------
 "abc.csv"
(1 row)

postgres=3D#

Wh= en I query the table outside anonymous block it is still there. So I am thi= nking may be I am missing some concept here or hitting a bug:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D
pos= tgres=3D# select min(user_name) from "abc.csv";
ERROR:  missing dat= a for column "database_name"
CONTEXT:  COPY abc.csv, line 1: "aa,bb= ,cc"
postgres=3D#
postgres=3D#
postgres=3D# select ftrelid::regc= lass::text from pg_foreign_table       &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;        where ftrelid::regclass::te= xt like '%abc.csv%';
  ftrelid  
-----------
 "abc.= csv"
(1 row)


Regards,
Virendra Kumar

------=_Part_1859024_69119251.1587076788133--