Last active
June 4, 2019 15:36
-
-
Save denisoster/01f2c5181f562c564d5100bbbbfd50f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| TRUNCATE invoice_footers; | |
| ALTER SEQUENCE invoice_footers_id_seq RESTART WITH 1; | |
| ALTER TABLE invoice_footers | |
| ADD COLUMN page varchar; | |
| ALTER TABLE invoice_footers | |
| ADD UNIQUE (page); | |
| CREATE OR REPLACE FUNCTION my_function(input json) | |
| RETURNS json | |
| LANGUAGE plpgsql AS | |
| $func$ | |
| DECLARE | |
| _key text; | |
| _value text; | |
| BEGIN | |
| FOR _key, _value IN | |
| SELECT * FROM json_each_text($1) | |
| LOOP | |
| INSERT INTO invoice_footers (adv_phrase, page) VALUES (_value, _key); | |
| END loop; | |
| RETURN input; | |
| END | |
| $func$; | |
| SELECT my_function('{"main": "", "did_service": "", "traffic_statistics": "", "capacity": "", "pstn_flat_rate_package": "", "other": ""}'); | |
| CREATE OR REPLACE FUNCTION test( in_array TEXT[] ) RETURNS void AS $$ | |
| DECLARE | |
| t TEXT; | |
| BEGIN | |
| FOREACH t IN ARRAY in_array LOOP | |
| INSERT INTO invoice_footers (adv_phrase, page) VALUES (text, page); | |
| END loop; | |
| END; | |
| $$ LANGUAGE plpgsql; | |
| SELECT test( array['a', 'b', 'c'] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment