fix tf-names and tableColumnNames

This commit is contained in:
Michael Hoennig 2024-09-15 18:21:08 +02:00
parent 79a81692db
commit 826773f22f
2 changed files with 9 additions and 12 deletions

View File

@ -11,27 +11,24 @@ create or replace function base.tableColumnNames( ofTableName text )
stable
language 'plpgsql' as $$
declare
ofTableName text default 'test.customer';
tableName text;
tableSchema text;
columns text[];
columnNames text;
begin
tableSchema := CASE
WHEN position('.' in ofTableName) > 0 THEN split_part(ofTableName, '.', 1)
END;
assert tableSchema = 'test', 'schema <> test';
ELSE 'public'
END;
tableName := CASE
WHEN position('.' in ofTableName) > 0 THEN split_part(ofTableName, '.', 2)
ELSE ofTableName
END;
assert tableName = 'customer', 'name <> customer';
columns := (select array(select column_name::text
from information_schema.columns
where table_name = tableName
and table_schema is not distinct from tableSchema));
and table_schema = tableSchema));
assert cardinality(columns) > 0, 'cannot determine columns of table ' || ofTableName ||
'("' || tableSchema || '"."' || tableName || '")';
return array_to_string(columns, ', ');

View File

@ -235,7 +235,7 @@ begin
*/
newColumns := 'new.' || replace(columnNames, ', ', ', new.');
sql := format($sql$
create or replace function %1$sInsert()
create function %1$s_instead_of_insert_tf()
returns trigger
language plpgsql as $f$
declare
@ -258,7 +258,7 @@ begin
instead of insert
on %1$s_rv
for each row
execute function %1$sInsert();
execute function %1$s_instead_of_insert_tf();
$sql$, targetTable);
execute sql;
@ -266,7 +266,7 @@ begin
Instead of delete trigger function for the restricted view.
*/
sql := format($sql$
create or replace function %1$sDelete()
create function %1$s_instead_of_delete_tf()
returns trigger
language plpgsql as $f$
begin
@ -287,7 +287,7 @@ begin
instead of delete
on %1$s_rv
for each row
execute function %1$sDelete();
execute function %1$s_instead_of_delete_tf();
$sql$, targetTable);
execute sql;
@ -297,7 +297,7 @@ begin
*/
if columnUpdates is not null then
sql := format($sql$
create or replace function %1$sUpdate()
create function %1$s_instead_of_update_tf()
returns trigger
language plpgsql as $f$
begin
@ -320,7 +320,7 @@ begin
instead of update
on %1$s_rv
for each row
execute function %1$sUpdate();
execute function %1$s_instead_of_update_tf();
$sql$, targetTable);
execute sql;
end if;