diff --git a/packages/nodes-base/nodes/Postgres/Postgres.node.ts b/packages/nodes-base/nodes/Postgres/Postgres.node.ts index 69aee12ada0f4..795c53f5f4b28 100644 --- a/packages/nodes-base/nodes/Postgres/Postgres.node.ts +++ b/packages/nodes-base/nodes/Postgres/Postgres.node.ts @@ -11,13 +11,14 @@ export class Postgres extends VersionedNodeType { name: 'postgres', icon: 'file:postgres.svg', group: ['input'], - defaultVersion: 2, + defaultVersion: 2.1, description: 'Get, add and update data in Postgres', }; const nodeVersions: IVersionedNodeType['nodeVersions'] = { 1: new PostgresV1(baseDescription), 2: new PostgresV2(baseDescription), + 2.1: new PostgresV2(baseDescription), }; super(nodeVersions, baseDescription); diff --git a/packages/nodes-base/nodes/Postgres/v2/actions/router.ts b/packages/nodes-base/nodes/Postgres/v2/actions/router.ts index 68289d5a87664..bc4115e8b4572 100644 --- a/packages/nodes-base/nodes/Postgres/v2/actions/router.ts +++ b/packages/nodes-base/nodes/Postgres/v2/actions/router.ts @@ -17,6 +17,7 @@ export async function router(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('postgres'); + const options = { nodeVersion: this.getNode().typeVersion }; - const { db } = (await Connections.getInstance(credentials)) as ConnectionsData; + const { db } = (await Connections.getInstance(credentials, options)) as ConnectionsData; try { const response = await db.any('SELECT schema_name FROM information_schema.schemata'); @@ -22,8 +23,9 @@ export async function schemaSearch(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('postgres'); + const options = { nodeVersion: this.getNode().typeVersion }; - const { db } = (await Connections.getInstance(credentials)) as ConnectionsData; + const { db } = (await Connections.getInstance(credentials, options)) as ConnectionsData; const schema = this.getNodeParameter('schema', 0, { extractValue: true, diff --git a/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts b/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts index acc6fb92472f3..646d7153d7a55 100644 --- a/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts +++ b/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts @@ -5,8 +5,9 @@ import { Connections } from '../transport'; export async function getColumns(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('postgres'); + const options = { nodeVersion: this.getNode().typeVersion }; - const { db } = (await Connections.getInstance(credentials)) as ConnectionsData; + const { db } = (await Connections.getInstance(credentials, options)) as ConnectionsData; const schema = this.getNodeParameter('schema', 0, { extractValue: true, diff --git a/packages/nodes-base/nodes/Postgres/v2/transport/index.ts b/packages/nodes-base/nodes/Postgres/v2/transport/index.ts index 76240a05ab704..8b78641678a5e 100644 --- a/packages/nodes-base/nodes/Postgres/v2/transport/index.ts +++ b/packages/nodes-base/nodes/Postgres/v2/transport/index.ts @@ -47,6 +47,15 @@ async function configurePostgres( ) { const pgp = pgPromise(); + if (typeof options.nodeVersion == 'number' && options.nodeVersion >= 2.1) { + // Always return dates as ISO strings + [pgp.pg.types.builtins.TIMESTAMP, pgp.pg.types.builtins.TIMESTAMPTZ].forEach((type) => { + pgp.pg.types.setTypeParser(type, (value: string) => { + return new Date(value).toISOString(); + }); + }); + } + if (options.largeNumbersOutput === 'numbers') { pgp.pg.types.setTypeParser(20, (value: string) => { return parseInt(value, 10);