views:

43

answers:

2

Hi,

I am doing some unit testing for a DAO that works with postgresql. Some of the SQL queries that my DAO uses involve the DATE function. Is there an in-memory database that supports functions similar to the ones that postgresql does?

Currently I am looking for support for the DATE function however, I obviously can see myself using other functions in the future.

+3  A: 

sqlite3 has in-memory support, and it has DATE functions.

duncan
awesome! thanks
Chris J
A: 

In linux you can create an "in memory database" with postgresql using a ramdisk. Quoting from a thread in postgresql mailing list:

In my opinion very nice solution is building part of PostgreSQL database in memory - below it is instruction how to build PostgreSQL schema in memory in Linux. I tested this with my ROLAP solution for recalculation MOLAP cubes in memory and then join with master cube (this speeds up proces about 10 times!!! - but in other solution may be different).

In grub (or other bootloader) you must declare ramdisk and then in OS:

mke2fs /dev/ram0
mkdir /mnt/ram0
mount /dev/ram0 /mnt/ram0
mkdir /mnt/ram0/pgspace
chown postgres:postgres mnt/ram0/pgspace

The "/mnt/ram0/pgspace" folder must be empty (ERROR: directory "/mnt/ram0" is not empty)

And then you may create tables (in this schema of course) and write to them.

I didn't tried this, I'm not 100% sure that this works without problems. Note also that in the same thread they suggest other db engine with in memory support, but no mention about DATE function. Other rdbms could benefit from ramdisk also if they have support for table space.

EDIT

Ex:

CREATE TABLESPACE inram LOCATION '/mnt/ram0/pgspace';
CREATE TABLE foo(i int) TABLESPACE inram;

foo table now should be an in-memory table.

mg
I don't really see how this could be applied to unit testing though.
Chris J
@Chris J: I hope I better answer your question. Anyway this would be an "that one is the one for you, this one is just an alternative" answer.
mg