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

FORMATing not being applied for queries which use WITH x as (SELECT 1) SELECT * FROM x. #102

Closed
UnamedRus opened this issue Dec 21, 2021 · 2 comments

Comments

@UnamedRus
Copy link

I do believe it happens because of this regexp.

if (query.match(/^(select|show|exists)/i)) {

Workaround is: manually write FORMAT JSON or whatever in your query.

@TimonKK
Copy link
Owner

TimonKK commented Jan 25, 2022

Hi, I published a fix for your case. Could you please upgrade the package and test it?

@xav-b
Copy link

xav-b commented Mar 24, 2022

@TimonKK thanks a ton for the fix, this seems to do the trick indeed. I used the code below that fails with version 2.4.2 with unexpected json, but works with the latest 2.4.4.

const CTE_SQL = `
WITH yolo AS (
  SELECT rand() AS a, rand(1) AS b, rand(number) AS c
  FROM numbers(3)
)

SELECT a, b, c FROM yolo
`

const OPTS = {
    url, port, ...,
    format: 'json',
}

async function main() {
  const rows = await ck.connect(OPTS).query(CTE_SQL).toPromise()
  console.log(rows)
   //  { a: 560152421, b: 3052471433, c: 25746393 },
   // { a: 3317286345, b: 3388181787, c: 2905723273 },
   // { a: 3213018093, b: 2268847078, c: 3820230708 }

}

main()

@TimonKK TimonKK closed this as completed Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants