fix tf-names and tableColumnNames
This commit is contained in:
parent
79a81692db
commit
826773f22f
@ -11,27 +11,24 @@ create or replace function base.tableColumnNames( ofTableName text )
|
|||||||
stable
|
stable
|
||||||
language 'plpgsql' as $$
|
language 'plpgsql' as $$
|
||||||
declare
|
declare
|
||||||
ofTableName text default 'test.customer';
|
|
||||||
tableName text;
|
tableName text;
|
||||||
tableSchema text;
|
tableSchema text;
|
||||||
columns text[];
|
columns text[];
|
||||||
columnNames text;
|
|
||||||
begin
|
begin
|
||||||
tableSchema := CASE
|
tableSchema := CASE
|
||||||
WHEN position('.' in ofTableName) > 0 THEN split_part(ofTableName, '.', 1)
|
WHEN position('.' in ofTableName) > 0 THEN split_part(ofTableName, '.', 1)
|
||||||
END;
|
ELSE 'public'
|
||||||
assert tableSchema = 'test', 'schema <> test';
|
END;
|
||||||
|
|
||||||
tableName := CASE
|
tableName := CASE
|
||||||
WHEN position('.' in ofTableName) > 0 THEN split_part(ofTableName, '.', 2)
|
WHEN position('.' in ofTableName) > 0 THEN split_part(ofTableName, '.', 2)
|
||||||
ELSE ofTableName
|
ELSE ofTableName
|
||||||
END;
|
END;
|
||||||
assert tableName = 'customer', 'name <> customer';
|
|
||||||
|
|
||||||
columns := (select array(select column_name::text
|
columns := (select array(select column_name::text
|
||||||
from information_schema.columns
|
from information_schema.columns
|
||||||
where table_name = tableName
|
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 ||
|
assert cardinality(columns) > 0, 'cannot determine columns of table ' || ofTableName ||
|
||||||
'("' || tableSchema || '"."' || tableName || '")';
|
'("' || tableSchema || '"."' || tableName || '")';
|
||||||
return array_to_string(columns, ', ');
|
return array_to_string(columns, ', ');
|
||||||
|
@ -235,7 +235,7 @@ begin
|
|||||||
*/
|
*/
|
||||||
newColumns := 'new.' || replace(columnNames, ', ', ', new.');
|
newColumns := 'new.' || replace(columnNames, ', ', ', new.');
|
||||||
sql := format($sql$
|
sql := format($sql$
|
||||||
create or replace function %1$sInsert()
|
create function %1$s_instead_of_insert_tf()
|
||||||
returns trigger
|
returns trigger
|
||||||
language plpgsql as $f$
|
language plpgsql as $f$
|
||||||
declare
|
declare
|
||||||
@ -258,7 +258,7 @@ begin
|
|||||||
instead of insert
|
instead of insert
|
||||||
on %1$s_rv
|
on %1$s_rv
|
||||||
for each row
|
for each row
|
||||||
execute function %1$sInsert();
|
execute function %1$s_instead_of_insert_tf();
|
||||||
$sql$, targetTable);
|
$sql$, targetTable);
|
||||||
execute sql;
|
execute sql;
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ begin
|
|||||||
Instead of delete trigger function for the restricted view.
|
Instead of delete trigger function for the restricted view.
|
||||||
*/
|
*/
|
||||||
sql := format($sql$
|
sql := format($sql$
|
||||||
create or replace function %1$sDelete()
|
create function %1$s_instead_of_delete_tf()
|
||||||
returns trigger
|
returns trigger
|
||||||
language plpgsql as $f$
|
language plpgsql as $f$
|
||||||
begin
|
begin
|
||||||
@ -287,7 +287,7 @@ begin
|
|||||||
instead of delete
|
instead of delete
|
||||||
on %1$s_rv
|
on %1$s_rv
|
||||||
for each row
|
for each row
|
||||||
execute function %1$sDelete();
|
execute function %1$s_instead_of_delete_tf();
|
||||||
$sql$, targetTable);
|
$sql$, targetTable);
|
||||||
execute sql;
|
execute sql;
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ begin
|
|||||||
*/
|
*/
|
||||||
if columnUpdates is not null then
|
if columnUpdates is not null then
|
||||||
sql := format($sql$
|
sql := format($sql$
|
||||||
create or replace function %1$sUpdate()
|
create function %1$s_instead_of_update_tf()
|
||||||
returns trigger
|
returns trigger
|
||||||
language plpgsql as $f$
|
language plpgsql as $f$
|
||||||
begin
|
begin
|
||||||
@ -320,7 +320,7 @@ begin
|
|||||||
instead of update
|
instead of update
|
||||||
on %1$s_rv
|
on %1$s_rv
|
||||||
for each row
|
for each row
|
||||||
execute function %1$sUpdate();
|
execute function %1$s_instead_of_update_tf();
|
||||||
$sql$, targetTable);
|
$sql$, targetTable);
|
||||||
execute sql;
|
execute sql;
|
||||||
end if;
|
end if;
|
||||||
|
Loading…
Reference in New Issue
Block a user