Repository: oguimbal/pg-mem

Issue #26: Support Sequelize : Must implement cross joins (carthesian products)
Created: 2021-01-05T19:37:58Z
Sequelize is generating requests using "comma-join-syntax", which is currently not supported.
👉 Failed query:

    SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'Users' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;;

💀 Syntax error at line 1 col 239:

  SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t,
                                                                                                                                                                                                                                                ^
Unexpected comma token: ",". Instead, I was expecting to see one of the following:

This syntax is not supported as of today because it was kind of harder to implement, since it can lead to cross-joins (carthesian products).
=> This must be done.
Unit test stub for sequelize:  src/tests/sequelize-real.spec.ts  (currently ignored)

Duplicate issue #125: Unexpected comma token: ","
Created: 2021-06-09T09:23:10Z
Using jest and sequelize, with sequelize-typescript, I am unable to get db.sync to work, as it fails with the error

	Error
	```js
	DatabaseError [SequelizeDatabaseError]: 💔 Your query failed to parse.
		This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
		If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.
	👉 Failed query:

		SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userStats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;;

	💀 Syntax error at line 1 col 239:

	SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t,
																																																													^
	Unexpected comma token: ",". Instead, I was expecting to see one of the following:

		- A "kw_left" token
		- A "kw_right" token
		- A "kw_full" token
		- A "kw_inner" token
		- A "kw_where" token
		- A "kw_group" token
		- A "kw_join" token
		- A "kw_order" token
		- A "kw_limit" token
		- A "kw_offset" token
		- A "kw_fetch" token
		- A "kw_union" token
		- A "semicolon" token


		at Query.formatError (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/postgres/query.js:406:16)
		at Query.run (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/postgres/query.js:96:18)
		at /Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/sequelize.js:638:16
		at PostgresQueryInterface.showIndex (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/abstract/query-interface.js:572:12)
		at Function.sync (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/model.js:1385:19)
		at Sequelize.sync (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/sequelize.js:816:35)
		at Object.initDb (/Users/<username>/documents/personal/pg-mem-test/__tests__/__utils__/MockPG.ts:44:9) {
	parent: QueryError: 💔 Your query failed to parse.
	This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
	If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.

	👉 Failed query:

		SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userStats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;;

	💀 Syntax error at line 1 col 239:

		SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t,
																																																													^
	Unexpected comma token: ",". Instead, I was expecting to see one of the following:

		- A "kw_left" token
		- A "kw_right" token
		- A "kw_full" token
		- A "kw_inner" token
		- A "kw_where" token
		- A "kw_group" token
		- A "kw_join" token
		- A "kw_order" token
		- A "kw_limit" token
		- A "kw_offset" token
		- A "kw_fetch" token
		- A "kw_union" token
		- A "semicolon" token


		at Object.parseSql (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/index.js:5344:13)
		at DbSchema.parse (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/index.js:6022:28)
		at DbSchema.queries (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/index.js:6030:27)
		at queries.next (<anonymous>)
		at DbSchema.query (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/src/datatypes/t-time.ts:42:17)
		at MemPg.query (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/index.js:13699:68)
		at query (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/postgres/query.js:80:227)
		at new Promise (<anonymous>)
		at Query.run (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/postgres/query.js:80:183)
		at /Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/sequelize.js:638:28
		at PostgresQueryInterface.showIndex (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/abstract/query-interface.js:572:12)
		at Function.sync (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/model.js:1385:19)
		at Sequelize.sync (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/sequelize.js:816:35)
		at Object.initDb (/Users/<username>/documents/personal/pg-mem-test/__tests__/__utils__/MockPG.ts:44:9) {
		data: {
		error: '💔 Your query failed to parse.\n' +
			'This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.\n' +
			'If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.\n' +
			'\n' +
			'👉 Failed query:\n' +
			'\n' +
			"    SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userStats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;;\n" +
			'\n' +
			'💀 Syntax error at line 1 col 239:\n' +
			'\n' +
			'  SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t,\n' +
			'                                                                                                                                                                                                                                                ^\n' +
			'Unexpected comma token: ",". Instead, I was expecting to see one of the following:\n' +
			'\n' +
			'    - A "kw_left" token\n' +
			'    - A "kw_right" token\n' +
			'    - A "kw_full" token\n' +
			'    - A "kw_inner" token\n' +
			'    - A "kw_where" token\n' +
			'    - A "kw_group" token\n' +
			'    - A "kw_join" token\n' +
			'    - A "kw_order" token\n' +
			'    - A "kw_limit" token\n' +
			'    - A "kw_offset" token\n' +
			'    - A "kw_fetch" token\n' +
			'    - A "kw_union" token\n' +
			'    - A "semicolon" token\n' +
			'\n',
		code: undefined
		},
		sql: "SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userStats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;",
		parameters: undefined
	},
	original: QueryError: 💔 Your query failed to parse.
	This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
	If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.

	👉 Failed query:

		SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userStats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;;

	💀 Syntax error at line 1 col 239:

		SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t,
																																																													^
	Unexpected comma token: ",". Instead, I was expecting to see one of the following:

		- A "kw_left" token
		- A "kw_right" token
		- A "kw_full" token
		- A "kw_inner" token
		- A "kw_where" token
		- A "kw_group" token
		- A "kw_join" token
		- A "kw_order" token
		- A "kw_limit" token
		- A "kw_offset" token
		- A "kw_fetch" token
		- A "kw_union" token
		- A "semicolon" token


		at Object.parseSql (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/index.js:5344:13)
		at DbSchema.parse (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/index.js:6022:28)
		at DbSchema.queries (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/index.js:6030:27)
		at queries.next (<anonymous>)
		at DbSchema.query (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/src/datatypes/t-time.ts:42:17)
		at MemPg.query (/Users/<username>/documents/personal/pg-mem-test/node_modules/pg-mem/index.js:13699:68)
		at query (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/postgres/query.js:80:227)
		at new Promise (<anonymous>)
		at Query.run (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/postgres/query.js:80:183)
		at /Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/sequelize.js:638:28
		at PostgresQueryInterface.showIndex (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/dialects/abstract/query-interface.js:572:12)
		at Function.sync (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/model.js:1385:19)
		at Sequelize.sync (/Users/<username>/documents/personal/pg-mem-test/node_modules/sequelize/lib/sequelize.js:816:35)
		at Object.initDb (/Users/<username>/documents/personal/pg-mem-test/__tests__/__utils__/MockPG.ts:44:9) {
		data: {
		error: '💔 Your query failed to parse.\n' +
			'This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.\n' +
			'If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.\n' +
			'\n' +
			'👉 Failed query:\n' +
			'\n' +
			"    SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userStats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;;\n" +
			'\n' +
			'💀 Syntax error at line 1 col 239:\n' +
			'\n' +
			'  SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t,\n' +
			'                                                                                                                                                                                                                                                ^\n' +
			'Unexpected comma token: ",". Instead, I was expecting to see one of the following:\n' +
			'\n' +
			'    - A "kw_left" token\n' +
			'    - A "kw_right" token\n' +
			'    - A "kw_full" token\n' +
			'    - A "kw_inner" token\n' +
			'    - A "kw_where" token\n' +
			'    - A "kw_group" token\n' +
			'    - A "kw_join" token\n' +
			'    - A "kw_order" token\n' +
			'    - A "kw_limit" token\n' +
			'    - A "kw_offset" token\n' +
			'    - A "kw_fetch" token\n' +
			'    - A "kw_union" token\n' +
			'    - A "semicolon" token\n' +
			'\n',
		code: undefined
		},
		sql: "SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userStats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;",
		parameters: undefined
	},
	sql: "SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userStats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;",
	parameters: undefined
	}

```


In order to get this error to trigger, I have created a small reproduction of the setup here.
If you have any more questions, just ask!

Closing comment (2021-07-12T12:05:25Z): Thanks for the detailed report, and sorry for the delay.
This is a duplicate of #26  but I dont have to work on it these days :(
It definitely is on my radar, though !