{"id":29892450,"url":"https://github.com/mfelici/rowgen","last_synced_at":"2025-09-10T11:35:19.770Z","repository":{"id":193924401,"uuid":"245865772","full_name":"mfelici/rowgen","owner":"mfelici","description":"Vertica User Defined Transform Function to generate rows","archived":false,"fork":false,"pushed_at":"2022-03-29T04:08:51.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-09-10T20:26:37.768Z","etag":null,"topics":["cpp","sql","udx","userdefined-functions","vertica"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfelici.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-03-08T18:23:32.000Z","updated_at":"2023-09-10T20:26:44.355Z","dependencies_parsed_at":"2023-09-10T20:36:46.293Z","dependency_job_id":null,"html_url":"https://github.com/mfelici/rowgen","commit_stats":null,"previous_names":["mfelici/rowgen"],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/mfelici/rowgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Frowgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Frowgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Frowgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Frowgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfelici","download_url":"https://codeload.github.com/mfelici/rowgen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Frowgen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268157504,"owners_count":24204755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","sql","udx","userdefined-functions","vertica"],"created_at":"2025-08-01T02:01:03.133Z","updated_at":"2025-08-01T02:02:31.969Z","avatar_url":"https://github.com/mfelici.png","language":"C++","readme":"﻿## What is ROWGEN().\nROWGEN() is a (very) simple User Defined Transform Function coded in C++ to generate rows. It just *counts* from 1 to the number passed as argument. Example:\n\n```sql\nSELECT ROWGEN(10) OVER();\nseries\n--------\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n(10 rows)\n```\n## What ROWGEN() can be used for.\nThe main use case for ROWGEN() is in-database data generation. We often have to create test data out of nothing and... while we can use a plethora of functions to generate **column** values, we also need to generate \"the other dimension\"... **rows**.\n\nWith Vertica people often use the *TIMESERIES trick* to generate rows, for example...\n\n```sql\nSELECT\n    ROW_NUMBER() OVER() \nFROM ( \n        SELECT 1 FROM (\n            SELECT NOW() + INTERVAL '1 second'  AS mytime \n            UNION ALL \n            SELECT NOW() + INTERVAL '10 seconds' AS mytime \n        ) x\n        TIMESERIES ts AS '1 second' OVER(ORDER BY mytime) \n     ) y\n;\n```\nwill produce **exactly** the same sequence of rows from 1 to 10 as ```SELECT ROWGEN(10) OVER()``` but - frankly speaking - I found the second much easier to remember :-)\n\n## Test data generation example.\nSuppose we want to generate 1,000 rows of test data with the following structure:\n- ```fname``` (first name) using a random name from a given list\n- ```lname``` (last name) using a random name from a given list\n- ```depid```(department id) in [100,200,300]\n- ```hdate``` (hire date) a random date after 01 Jan 2001\n- ```salary``` value between 10,000 and 19,000\n\nWe can use ROWGEN and Vertica's ARRAY data type and write something like this:\n```sql\nSELECT \n    (ARRAY['Ann','Elizabeth','Lucy','John','Ellen','Robert','Andrew','Mary','Matt'])\n        [RANDOMINT(9)]::VARCHAR AS fname,\n    (ARRAY['Gates','Lee','Ellison','Ross','Smith','Davis','Kennedy','Clark','Moore','Taylor'])\n        [RANDOMINT(10)]::VARCHAR AS lname,\n    ( RANDOMINT(3) + 1 ) * 100 AS depid,\n    '2001-01-01'::DATE + RANDOMINT(365*10) AS hdate,\n    (10000 + RANDOM()*9000)::NUMERIC(7,2) AS salary\nFROM\n    ( SELECT ROWGEN(1000) OVER() ) x;\n   fname   |  lname  | depid |    hdate   |  salary  \n-----------+---------+-------+------------+----------\n Mary      | Clark   |   200 | 2003-05-08 | 12512.02\n Andrew    | Lee     |   300 | 2010-09-12 | 17046.66\n Ellen     | Clark   |   100 | 2002-06-04 | 12710.49\n Mary      | Kennedy |   200 | 2008-04-27 | 18996.75\n Ann       | Clark   |   300 | 2006-02-19 | 14206.84\n John      | Davis   |   100 | 2003-09-05 | 10777.43\n Robert    | Smith   |   200 | 2004-03-02 | 12434.80\n John      | Moore   |   100 | 2007-10-07 | 14213.92\n Elizabeth | Gates   |   200 | 2005-02-01 | 16685.84\n Ann       | Davis   |   300 | 2003-08-18 | 16592.06\n Mary      | Gates   |   300 | 2007-12-07 | 16869.87\n Matt      | Ross    |   200 | 2004-08-28 | 12944.05\n Matt      | Clark   |   100 | 2007-05-02 | 12096.31\n Robert    | Davis   |   300 | 2008-10-21 | 10342.12\n Lucy      | Moore   |   200 | 2005-10-12 | 12652.80\n Mary      | Taylor  |   200 | 2004-03-10 | 15921.94\n Robert    | Taylor  |   200 | 2007-09-25 | 16721.34\n Ellen     | Lee     |   200 | 2008-12-08 | 10411.04\n Andrew    | Gates   |   300 | 2009-09-23 | 18468.49\n...\n```\n## How to install ROWGEN()\n- First step is to compile the source code: ```make```\n- Then - as dbadmin - deploy the code in Vertica: ```make deploy```\n- You can run ```make test``` to check everything is ok\n\nPlease have a look to the Makefile before running ```make``` and change it if needed.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfelici%2Frowgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfelici%2Frowgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfelici%2Frowgen/lists"}