Open zookatron opened 10 months ago
Same issue using :
9.0.1
2.7.1
@oguimbal Any hints to where we can start if we want to fix this? I just started using pg-mem and am open to contributing to this issue.
Found a workaround. Since it's evaluating only once, a peek through the code suggested that it's simply checking for the type of function and evaluating in case it's a function. So, double wrapping the evaluator works. For the above example, this should work,
database.public.registerFunction({
name: 'uuid',
args: [],
returns: DataType.uuid,
implementation: () => () => randomUUID(),
});
Or when using the uuid package,
schema.registerFunction({
name: 'uuid_generate_v4',
returns: DataType.uuid,
implementation: () => v4
});
Describe the bug
The Postgres documentation specifically mentions that default values should be evaluated when a record is inserted, not when the table is created: https://www.postgresql.org/docs/current/ddl-default.html The current implementation seems to evaluate default values at table creation time, breaking many common default value use cases.
To Reproduce
package.json:
index.js:
pg-mem version
2.6.13