mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Postgres Node): Upsert does not fetch columns when schema other then public (#6643)
This commit is contained in:
@@ -337,16 +337,18 @@ export async function getTableSchema(
|
||||
return columns;
|
||||
}
|
||||
|
||||
export async function uniqueColumns(db: PgpDatabase, table: string) {
|
||||
export async function uniqueColumns(db: PgpDatabase, table: string, schema = 'public') {
|
||||
// Using the modified query from https://wiki.postgresql.org/wiki/Retrieve_primary_key_columns
|
||||
// `quote_ident` - properly quote and escape an identifier
|
||||
// `::regclass` - cast a string to a regclass (internal type for object names)
|
||||
const unique = await db.any(
|
||||
`
|
||||
SELECT DISTINCT a.attname
|
||||
FROM pg_index i JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)
|
||||
WHERE i.indrelid = quote_ident($1)::regclass
|
||||
WHERE i.indrelid = (quote_ident($1) || '.' || quote_ident($2))::regclass
|
||||
AND (i.indisprimary OR i.indisunique);
|
||||
`,
|
||||
[table],
|
||||
[schema, table],
|
||||
);
|
||||
return unique as IDataObject[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user