Re: Generating a SQL Server population routine - Mailing list pgsql-general

From Mike Mascari
Subject Re: Generating a SQL Server population routine
Date
Msg-id 3F81B176.3060701@mascari.com
Whole thread Raw
In response to Generating a SQL Server population routine  (Martin_Hurst@dom.com)
List pgsql-general
Martin_Hurst@dom.com wrote:

> Has some one come up with a similar type script that could be used in a
> Postgresql database?

> The script below was created for a SQLServer database.
> Thx,
> -Martin

I haven't. But I was wondering if a general purpose tuple-generating
function, which would be trivial to implement, might be worthwhile in
PostgreSQL or perhaps added to Joe Conway's tablefunc module.
Something like:

tuple_generator(integer)

which returns a set of numbers whose elements are the integer values
between 1 and the number supplied.

You could then create any number of pseudo-duplicates (can't violate
the candidate key, obviously) from a single-record table like so:

INSERT INTO employees (name, salary)
SELECT employees.name, employees.salary
FROM employees, tuple_generator(1000)
WHERE employees.employeeid = 1;

You could easily build a script to fill your database by querying
pg_class.relname and feeding the output to psql.

It would also be useful for handling sparse date and time data:

SELECT day_of_year,
(SELECT COALESCE(SUM(purchases.qty), 0)
 FROM purchases
 WHERE EXTRACT(doy FROM purchases.sale_date) = day_of_year)
FROM tuple_generator(366) AS day_of_year
ORDER BY day_of_year;

Mike Mascari
mascarm@mascari.com
















pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Adding Indexes to Functions
Next
From: Bruce Momjian
Date:
Subject: Re: PostgreSQL Beta4 Tag'd and Bundle'd ...