Skip to content

Question: how to properly set datestyle on pooled connections #1393

Closed

Description

@bydga

When using the pool.connect & client.release approach, I'm setting the set datestyle = iso mdy as a first query to have my date-types parsed properly.

However, how to do it with the pool.query call? Since the connection returned is random - and might be an existing one recently returned to the pool as well as a newly established one..

Im not sure, if setting pg.types.setTypeParser for all the date/datetime/timestamp with/without timezone is a way I want to go..

Suggestions? :)

Activity

  1. charmander commented on Aug 1, 2017

    @charmander
    Collaborator

    You can create a client type for use with the pool providing custom startup configuration:

    const pool = new pg.Pool({
        Client: class extends pg.Client {
            getStartupConf() {
                return Object.assign(super.getStartupConf(), {
                    DateStyle: 'ISO,MDY',
                });
            }
        },
        ⋮
    });

    It might be nice to have an option along these lines, though:

    class pool = new pg.Pool({
        connectionOptions: {
            DateStyle: 'ISO,MDY',
        },
        ⋮
    });
  2. bydga commented on Aug 1, 2017

    @bydga
    Author

    hm, i've solved it by doing

    pool.on "connect", (client) ->
        client.query "SET DATESTYLE = iso, mdy"

    but your solution looks better :)

  3. brianc commented on Aug 7, 2017

    @brianc
    Owner

    I added this to the documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions