Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set DATESTYLE on new connections #645

Closed
googol opened this issue Jul 19, 2023 · 5 comments · Fixed by #707
Closed

How to set DATESTYLE on new connections #645

googol opened this issue Jul 19, 2023 · 5 comments · Fixed by #707

Comments

@googol
Copy link

googol commented Jul 19, 2023

Hi,

I'm looking for a way to automatically set DATESTYLE on all new connections opened by the node pool, to facilitate parsing timestamp values into temporal instants, but I'm not finding anything that could do that.

node-postgres has the connect event on it's node pool that allows executing sql on all new connections before they are used, is there anything similar, or would you be open to adding that sort of functionality?

@porsager
Copy link
Owner

porsager commented Jul 19, 2023

const sql = postgres({
  connection: { 
    DateStyle: 'your thing here'
  }
})

@googol
Copy link
Author

googol commented Jul 19, 2023

Oh that was simpler than expected, thanks!

I had a hunch that the connection prop could be related, it's just that only the application_name is documented anywhere. Is there some list of what connection parameters can be set via this object?

@porsager
Copy link
Owner

Hehe, yeah 😊

There's quite a good list here : https://www.postgresql.org/docs/current/runtime-config-client.html

Would be good to have a section in the docs for this, you're mouthe first to ask. What did you search for in the readme before posting here?

@googol
Copy link
Author

googol commented Jul 19, 2023

I looked for the specific thing, datestyle, then set search_path with a couple of variations, then scanned for anything about connection startup. Looked for those in the issues as well.

Adding a link to that documentation page in the documentation about the connection config prop would be a good start with regard to documenting it's use. Is application_name something specific to postgresjs btw, it's not listed on that page?

In the end my issue wasn't about the datestyle after all, it was just that I had to override the default type parser for timestamps in postgresjs. The project I'm working on uses Drizzle with postgresjs, and it has it's own layer of type conversions on top. I was using that to convert my timestamps to Temporal.Instants. The documentation and source indicated that the builtin timestamp parser converts from string to Date, but the incoming value had actually been converted to a Date already by postgresjs. Maybe this helps someone with similar issues :D

@porsager
Copy link
Owner

Very nice @googol !! thanks for the explanation. I'll just reopen the issue to track adding this to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants