Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

JSON not a valid type for parameterized query #1320

@Sese-Schneider

Description

@Sese-Schneider

Summary

When using parameterized queries with NULLABLE values one has to provide the types field in case a parameter is null.
The check getTypeDescriptorFromProvidedType_ fails with Invalid type provided: "JSON".

Stacktrace
>  Error: Invalid type provided: "JSON"
>      at BigQuery.getTypeDescriptorFromProvidedType_ (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\build\src\bigquery.js:741:19)
>      at BigQuery.valueToQueryParameter_ (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\build\src\bigquery.js:851:38)
>      at BigQuery.createQueryJob (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\build\src\bigquery.js:968:55)
>      at BigQuery.wrapper (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\node_modules\@google-cloud\promisify\build\src\index.js:30:35)
>      at BigQuery.query (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\build\src\bigquery.js:1218:14)     
>      at Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\node_modules\@google-cloud\promisify\build\src\index.js:57:28
>      at new Promise (<anonymous>)
>      at BigQuery.wrapper (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\node_modules\@google-cloud\promisify\build\src\index.js:42:16)
>      at Y:\[REDACTED]\backend\functions\lib\[REDACTED]\import.js:40:50
>      at Array.map (<anonymous>)

Looking at the sourcecode it looks like the type JSON was not implemented.

static getTypeDescriptorFromProvidedType_(
providedType: string | ProvidedTypeStruct | ProvidedTypeArray
): ValueType {
// The list of types can be found in src/types.d.ts
const VALID_TYPES = [
'DATE',
'DATETIME',
'TIME',
'TIMESTAMP',
'BYTES',
'NUMERIC',
'BIGNUMERIC',
'BOOL',
'INT64',
'FLOAT64',
'STRING',
'GEOGRAPHY',
'ARRAY',
'STRUCT',
];

even though it should have been according to the comment

// The list of types can be found in src/types.d.ts

where it actually can be found:

nodejs-bigquery/src/types.d.ts

Lines 3592 to 3611 in 4ebe5da

typeKind?:
| 'TYPE_KIND_UNSPECIFIED'
| 'INT64'
| 'BOOL'
| 'FLOAT64'
| 'STRING'
| 'BYTES'
| 'TIMESTAMP'
| 'DATE'
| 'TIME'
| 'DATETIME'
| 'INTERVAL'
| 'GEOGRAPHY'
| 'NUMERIC'
| 'BIGNUMERIC'
| 'JSON'
| 'ARRAY'
| 'STRUCT'
| 'RANGE';
};

Steps to reproduce

Run a parameterized query with a column of datatype JSON/NULLABLE

new BigQuery().query({
  query: `
    INSERT INTO
      database.table (data)
    VALUES
     (@data)
  `,
  params:  { data: null },
  types: { data: "JSON" },
})
Environment
- OS: Windows
- Node.js version: 18.13.0
- npm version: 9.8.1
- `@google-cloud/bigquery` version: 7.3.0

Sidenote: Same is true for the new datatype RANGE

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/nodejs-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions