-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vectorizer): use format_type to get primary key data types
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
projects/extension/sql/incremental/017-upgrade-source-pk.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
do language plpgsql $block$ | ||
declare | ||
_vec ai.vectorizer; | ||
_source pg_catalog.oid; | ||
_source_pk pg_catalog.jsonb; | ||
begin | ||
for _vec in (select * from ai.vectorizer) | ||
loop | ||
_source = pg_catalog.to_regclass(pg_catalog.format('%I.%I', _vec.source_schema, _vec.source_table)); | ||
if _source is null then | ||
continue; | ||
end if; | ||
|
||
select pg_catalog.jsonb_agg(x) into _source_pk | ||
from | ||
( | ||
select e.attnum, e.pknum, a.attname, pg_catalog.format_type(y.oid, a.atttypmod) as typname | ||
from pg_catalog.pg_constraint k | ||
cross join lateral pg_catalog.unnest(k.conkey) with ordinality e(attnum, pknum) | ||
inner join pg_catalog.pg_attribute a | ||
on (k.conrelid operator(pg_catalog.=) a.attrelid | ||
and e.attnum operator(pg_catalog.=) a.attnum) | ||
inner join pg_catalog.pg_type y on (a.atttypid operator(pg_catalog.=) y.oid) | ||
where k.conrelid operator(pg_catalog.=) _source | ||
and k.contype operator(pg_catalog.=) 'p' | ||
) x; | ||
|
||
if _source_pk is null then | ||
continue; | ||
end if; | ||
|
||
update ai.vectorizer u set source_pk = _source_pk | ||
where u.id = _vec.id | ||
; | ||
end loop; | ||
end; | ||
$block$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters