Repository navigation
Open
Open
Copy link
Labels
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).regressionFor issues and PRs. A bug that does not happen in an earlier version of Sequelize.
Description
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Bug Description
When using Sequelize 7 with PostgreSQL, if two schemas contain a table with the same name, sequelize.sync() (or any operation that triggers table introspection) fails with the following error:
ERROR: more than one row returned by a subquery used as an expression
Reproducible Example
Here is the link to the SSCCE for this issue:
What do you expect to happen?
sync is success
What is actually happening?
ERROR: more than one row returned by a subquery used as an expression
SELECT
pk.constraint_type AS "Constraint",
c.column_name AS "Field",
c.column_default AS "Default",
c.is_nullable AS "Null",
(
CASE
WHEN c.udt_name = 'hstore' THEN c.udt_name
ELSE c.data_type
END
) || (
CASE
WHEN c.character_maximum_length IS NOT NULL THEN '(' || c.character_maximum_length || ')'
ELSE ''
END
) AS "Type",
(
SELECT
array_agg(e.enumlabel)
FROM
pg_catalog.pg_type t
JOIN pg_catalog.pg_enum e ON t.oid = e.enumtypid
WHERE
t.typname = c.udt_name
) AS "special",
(
SELECT
pgd.description
FROM
pg_catalog.pg_statio_all_tables AS st
INNER JOIN pg_catalog.pg_description pgd ON (pgd.objoid = st.relid)
WHERE
c.ordinal_position = pgd.objsubid
AND c.table_name = st.relname
) AS "Comment"
FROM
information_schema.columns c
LEFT JOIN (
SELECT
tc.table_schema,
tc.table_name,
cu.column_name,
tc.constraint_type
FROM
information_schema.TABLE_CONSTRAINTS tc
JOIN information_schema.KEY_COLUMN_USAGE cu ON tc.table_schema = cu.table_schema
AND tc.table_name = cu.table_name
AND tc.constraint_name = cu.constraint_name
AND tc.constraint_type = 'PRIMARY KEY'
) pk ON pk.table_schema = c.table_schema
AND pk.table_name = c.table_name
AND pk.column_name = c.column_name
WHERE
c.table_name = 'example_book'
AND c.table_schema = 'meadmin'
true sql:
SELECT
pk.constraint_type AS "Constraint",
c.column_name AS "Field",
c.column_default AS "Default",
c.is_nullable AS "Null",
(
CASE
WHEN c.udt_name = 'hstore' THEN c.udt_name
ELSE c.data_type
END
) || (
CASE
WHEN c.character_maximum_length IS NOT NULL THEN '(' || c.character_maximum_length || ')'
ELSE ''
END
) AS "Type",
(
SELECT array_agg(e.enumlabel)
FROM pg_catalog.pg_type t
JOIN pg_catalog.pg_enum e ON t.oid = e.enumtypid
WHERE t.typname = c.udt_name
) AS "special",
(
SELECT pgd.description
FROM pg_catalog.pg_statio_all_tables AS st
INNER JOIN pg_catalog.pg_description pgd ON (pgd.objoid = st.relid)
WHERE c.ordinal_position = pgd.objsubid
AND c.table_name = st.relname
AND st.schemaname = c.table_schema -- ✅ 加上 schema 过滤
) AS "Comment"
FROM information_schema.columns c
LEFT JOIN (
SELECT
tc.table_schema,
tc.table_name,
cu.column_name,
tc.constraint_type
FROM information_schema.TABLE_CONSTRAINTS tc
JOIN information_schema.KEY_COLUMN_USAGE cu
ON tc.table_schema = cu.table_schema
AND tc.table_name = cu.table_name
AND tc.constraint_name = cu.constraint_name
AND tc.constraint_type = 'PRIMARY KEY'
) pk
ON pk.table_schema = c.table_schema
AND pk.table_name = c.table_name
AND pk.column_name = c.column_name
WHERE c.table_name = 'example_demo'
AND c.table_schema = 'meadmin';
Environment
- Sequelize version: 7.0.0-alpha.48
- Node.js version: 22.15.0
- If TypeScript related: TypeScript version:
- Database & Version: pgsql
- Connector library & Version: "@sequelize/postgres": "7.0.0-alpha.48",
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I will need guidance.
- No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
Metadata
Metadata
Assignees
Labels
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).regressionFor issues and PRs. A bug that does not happen in an earlier version of Sequelize.
Activity