Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres issue with getting tables for a schema which has space in its name #119

Open
pavansandeep2910 opened this issue Jun 9, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@pavansandeep2910
Copy link

pavansandeep2910 commented Jun 9, 2022

code:

const inspector = schemaInspector(knex);
inspector.withSchema('test schema')
await inspector.tables();

error:

SELECT
        rel.relname AS name
      FROM
        pg_class rel
      WHERE
        rel.relnamespace IN ('test schema'::regnamespace)
        AND rel.relkind = 'r'
      ORDER BY rel.relname
     - invalid name syntax
    at Parser.parseErrorMessage (/Users/pavan/Documents/node-project/node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/Users/pavan/Documents/node-project/node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/Users/pavan/Documents/node-project/node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/Users/pavan/Documents/node-project/node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 96,
  severity: 'ERROR',
  code: '42602',
  detail: undefined,
  hint: undefined,
  position: '116',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'regproc.c',
  line: '1890',
  routine: 'stringToQualifiedNameList'
}
@pavansandeep2910 pavansandeep2910 changed the title Issue with getting tables for a schema which has space in its name - postgres Postgres issue with getting tables for a schema which has space in its name Jun 9, 2022
@rijkvanzanten
Copy link
Collaborator

What version of Postgres are you using?

@pavansandeep2910
Copy link
Author

What version of Postgres are you using?

14.3

@rijkvanzanten
Copy link
Collaborator

rijkvanzanten commented Jun 9, 2022

Looks like

SELECT
        rel.relname AS name
      FROM
        pg_class rel
      WHERE
        rel.relnamespace IN ('test schema'::regnamespace)
        AND rel.relkind = 'r'
      ORDER BY rel.relname

is throwing an error, whereas

SELECT
        rel.relname AS name
      FROM
        pg_class rel
      WHERE
        rel.relnamespace IN ('"test schema"'::regnamespace)
        AND rel.relkind = 'r'
      ORDER BY rel.relname

works as expected.

This should be able to be resolved by adding an additional set of quotes in these pieces:

const schemaIn = this.explodedSchema.map(
(schemaName) => `${this.knex.raw('?', [schemaName])}::regnamespace`
);

Wanna open a PR for that @pavansandeep2910?

@rijkvanzanten rijkvanzanten added the bug Something isn't working label Jun 9, 2022
@pavansandeep2910

This comment was marked as resolved.

@rijkvanzanten

This comment was marked as resolved.

@pavansandeep2910
Copy link
Author

Looks like

SELECT
        rel.relname AS name
      FROM
        pg_class rel
      WHERE
        rel.relnamespace IN ('test schema'::regnamespace)
        AND rel.relkind = 'r'
      ORDER BY rel.relname

is throwing an error, whereas

SELECT
        rel.relname AS name
      FROM
        pg_class rel
      WHERE
        rel.relnamespace IN ('"test schema"'::regnamespace)
        AND rel.relkind = 'r'
      ORDER BY rel.relname

works as expected.

This should be able to be resolved by adding an additional set of quotes in these pieces:

const schemaIn = this.explodedSchema.map(
(schemaName) => `${this.knex.raw('?', [schemaName])}::regnamespace`
);

Wanna open a PR for that @pavansandeep2910?

I am happy to raise the PR

@Fasunle
Copy link

Fasunle commented Aug 30, 2022

Hello @pavansandeep2910 @rijkvanzanten

May I work on this bug?

@pavansandeep2910
Copy link
Author

@Fasunle Yes, please. I am sorry for not continuing to work on this issue. I was and am currently busy with some other work. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants