Skip to content

Instantly share code, notes, and snippets.

@orx0r
Last active September 15, 2016 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orx0r/cf4bbc1156ad8a8e8104627e366cd596 to your computer and use it in GitHub Desktop.
Save orx0r/cf4bbc1156ad8a8e8104627e366cd596 to your computer and use it in GitHub Desktop.
```pl/pgsql
do $$
declare
item text;
BEGIN
DELETE FROM table_realtion
WHERE rel1 = 2;
FOREACH item IN ARRAY string_to_array('1#2#5#', '#')
LOOP
RAISE INFO '%', pg_typeof(item);
if item <> '' then
INSERT INTO table_realtion (rel1_id, rel1_id)
VALUES (2, item::int); -- или: ... , CAST(item AS integer);
end if;
END LOOP;
end;
$$
language plpgsql;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment