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 1kw7AQ-0000H0-7y for pgsql-general@arkaria.postgresql.org; Sun, 03 Jan 2021 17:27:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kw7AP-0001Tj-6A for pgsql-general@arkaria.postgresql.org; Sun, 03 Jan 2021 17:27:45 +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 1kw7AO-0001Tc-St for pgsql-general@lists.postgresql.org; Sun, 03 Jan 2021 17:27:44 +0000 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kw7AL-0002OF-Qc for pgsql-general@lists.postgresql.org; Sun, 03 Jan 2021 17:27:44 +0000 Received: by mail-il1-x12e.google.com with SMTP id k8so23241516ilr.4 for ; Sun, 03 Jan 2021 09:27:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=QO3SEhWUVFqX0MxJPHkV/BkU/CRC4mruF0lU5BR2eWk=; b=UjzSrW/snaLPozSTy1LwWtYsqClZknciIoRglMiBlP5xrknqYkNc+kXYqXB/gWvogW hC4t2z1Ab3PpQrTSt1z77B8pvBjPUA1VsxVBwSNpHkukAszfrvWBqq59ExdEA55Nlf1v foE/blOG8BIpvF7ugUZmeprs+uY0zYH3B8bWf6kpP8sD358dW/lk8GPA/g1ai7znonZP 3PL7zWHf3WeP6t588IuRoUn6H5oMQ8e1Vaw2F5gcH2HLHBJGA3RsP5m1aTJv1v5mkRTw DBKjqerZX376VtEC1tmBIr7TN0/m/dhIHIkipNfehPMs7Xm9cPTNpgXuS6iB5O/y9jzJ GH7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=QO3SEhWUVFqX0MxJPHkV/BkU/CRC4mruF0lU5BR2eWk=; b=EMXfU5wPcwuzj3lEBH7H33+gZihiXEIw051ria30O67uxdJIfF7dR8abpjbfvin8nR 2mna8Zd1MvB6MO5oQFr47glJTUfHux/Aa9Oc5deeB1B8WaBD3tab8apVDX5CQ5lvVSPn CAwE16rYSeeh9pQCjvW30T3LyChp22my4JiSkCwSVIO2IwX7p/zWZOMN3XApliigL6cu X3cF7ypORBsN8ZT1KdzTQtC1uyYBLwwyDQzTG2X5/av+EG1tO5DEFR3mzde2mb+VTK5E ftCFIEVwhCRzH5Ydy84fEsj6Px5txpSdElHUKByVxypG8I56cm5dYZB+7WZAMidPP6ts aUwQ== X-Gm-Message-State: AOAM533G2wO3cVM+DEwtMKvRap5xYVAE37gEyc4XpaLv/9lBo34dVbwY 6mnqqbHCRuiq6S09ngsq0oJ7Ix5Sy+b7hA== X-Google-Smtp-Source: ABdhPJzmheTGdGShDGDirftgizraromsvGkiUXPfCgn+9tWpdkOiMRrvSDc+M7+YP2wuF1XbPtrouA== X-Received: by 2002:a92:cb0d:: with SMTP id s13mr67654266ilo.73.1609694859809; Sun, 03 Jan 2021 09:27:39 -0800 (PST) Received: from ?IPv6:2601:681:5500:dde0:4d1d:2a8d:c4d0:8cbe? ([2601:681:5500:dde0:4d1d:2a8d:c4d0:8cbe]) by smtp.gmail.com with ESMTPSA id v6sm38654374ilo.61.2021.01.03.09.27.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Jan 2021 09:27:39 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Rob Sargent Mime-Version: 1.0 (1.0) Subject: Re: Possible trigger bug? function call argument literalised Date: Sun, 3 Jan 2021 10:27:38 -0700 Message-Id: References: <20210103180840.Horde.Fe4qNP3Uviz_9c6aPfxBTS2@webmail.gelassene-pferde.biz> Cc: PostgreSQL General In-Reply-To: <20210103180840.Horde.Fe4qNP3Uviz_9c6aPfxBTS2@webmail.gelassene-pferde.biz> To: Thiemo Kellner X-Mailer: iPhone Mail (18C66) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Jan 3, 2021, at 10:08 AM, Thiemo Kellner w= rote: >=20 > =EF=BB=BFHi >=20 > I created a table with trigger and according trigger and trigger function a= s >=20 > drop table if exists CALCULATION_METHOD cascade; > create table CALCULATION_METHOD (ID > uuid > not null > default uuid_generate_v4(), > METHOD_NAME > text > not null, > DB_ROUTINE_NAME > name > not null, > ENTRY_PIT > timestamptz > not null > default transaction_timestamp(), > REMARKS > text, > constraint CALCULATION_METHOD_PK > primary key (ID), > constraint CALCULATION_METHOD_UQ > unique (DB_ROUTINE_NAME)); >=20 > create or replace function METHOD_CHECK() > returns trigger > language plpgsql > stable > as > $body$ > declare > V_COUNT smallint; > begin > if TG_NARGS !=3D 1 then > raise > exception > using > message =3D 'METHOD_CHECK expects the schema name to be pas= sed and nothing more! There have been passed ' || > TG_NARGS || ' arguments.', > hint =3D 'Please check the trigger "' || TG_NAME || > '" on table "' || TG_TABLE_NAME || '" in schema "'= || > TG_TABLE_SCHEMA || '".'; > end if; > select COUNT(*) into V_COUNT > from INFORMATION_SCHEMA.ROUTINES > where ROUTINE_SCHEMA =3D TG_ARGV[1] > and ROUTINE_NAME =3D NEW.DB_ROUTINE_NAME; > if V_COUNT !=3D 1 then > raise exception ' expects the schema name to be passed!'; > end if; > insert into TG_TABLE_SCHEMA.TG_TABLE_NAME values (NEW.*); > return NULL; > end; > $body$; >=20 > create trigger CALCULATION_METHOD_BR_IU > before insert on CALCULATION_METHOD > for each row > execute function METHOD_CHECK(current_schema); >=20 >=20 > Executing such, the string "current_schema" gets literalised, i.e. single q= uoted: > norge=3D# \d calculation_method > Table "public.calculation_method" > Column | Type | Collation | Nullable | = Default > -----------------+--------------------------+-----------+----------+------= ------------------- > id | uuid | | not null | uuid_g= enerate_v4() > method_name | text | | not null | > db_routine_name | name | | not null | > entry_pit | timestamp with time zone | | not null | transa= ction_timestamp() > remarks | text | | | > Indexes: > "calculation_method_pk" PRIMARY KEY, btree (id) > "calculation_method_uq" UNIQUE CONSTRAINT, btree (db_routine_name) > Triggers: > calculation_method_br_iu BEFORE INSERT ON calculation_method FOR EACH R= OW EXECUTE FUNCTION method_check('current_schema') >=20 >=20 > I am using > norge=3D# select version(); > versi= on > --------------------------------------------------------------------------= -------------------------------------------------------------------------- > PostgreSQL 12.5 on x86_64-suse-linux-gnu, compiled by gcc (SUSE Linux) 10.= 2.1 20201028 [revision a78cd759754c92cecbf235ac9b447dcdff6c6e2f], 64-bit >=20 > I strongly feel this is a bug, at least no intention at all from my side. H= owever, before filing a bug, I wanted to get your opinion on that. Maybe it i= s just a problem of the openSUSE Tumbleweed repository. >=20 > I would appreciate your two dimes. Kind regards >=20 > Thiemo >=20 > --=20 > S/MIME Public Key: https://oc.gelassene-pferde.biz/index.php/s/eJuAUFONag6= ofnH > Signal (Safer than WhatsApp): +49 1578 7723737 > Threema (Safer than WhatsApp): A76MKH3J > Handys: +41 78 947 36 21 | +49 1578 772 37 37 >=20 >=20 The function definition doesn=E2=80=99t name any parameters? >=20