I have table like next
Name |
---|
tblname_01 |
tblname_02 |
tblname_03 |
CREATE TABLE test (
name varchar(128)
);
INSERT INTO test
VALUES
('tblname_01'),
('tblname_02'),
('tblname_03');
SELECT * FROM test;
I would like to get next output:
{
"rule-type": "selection",
"rule-id": "1001",
"rule-name": "1001",
"object-locator": {
"schema-name": "%",
"table-name": "tblname_01"
},
"rule-action": "include",
"filters": []
},
{
"rule-type": "selection",
"rule-id": "1002",
"rule-name": "1002",
"object-locator": {
"schema-name": "%",
"table-name": "tblname_02"
},
"rule-action": "include",
"filters": []
},
{
"rule-type": "selection",
"rule-id": "1003",
"rule-name": "1003",
"object-locator": {
"schema-name": "%",
"table-name": "tblname_03"
},
"rule-action": "include",
"filters": []
}
Actually, I need to create JSON-file from more then 100 names of tables. But, first tried to create JSON-files from three names of tables, but I didn’t.
2
Answers
Based on your data you could do something like this
Fiddle to test
For the purposes of constructing a numerical sequence of
rule
s, you can usegenerate_series
and join the original table back on to it:See fiddle.