From: | Mike Mascari <mascarm(at)mascari(dot)com> |
---|---|
To: | Martin_Hurst(at)dom(dot)com |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Generating a SQL Server population routine |
Date: | 2003-10-06 18:16:22 |
Message-ID: | 3F81B176.3060701@mascari.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Martin_Hurst(at)dom(dot)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(at)mascari(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2003-10-06 18:21:20 | Re: Postgres low end processing. |
Previous Message | Stephan Szabo | 2003-10-06 18:01:34 | Re: Adding Indexes to Functions |