@@ -809,7 +809,9 @@ export class BigQuery extends common.Service {
809809 let typeName ;
810810
811811 if ( value === null ) {
812- throw new Error ( 'Type must be provided for null values.' ) ;
812+ throw new Error (
813+ "Parameter types must be provided for null values via the 'types' field in query options."
814+ ) ;
813815 }
814816
815817 if ( value instanceof BigQueryDate ) {
@@ -826,7 +828,9 @@ export class BigQuery extends common.Service {
826828 typeName = 'NUMERIC' ;
827829 } else if ( Array . isArray ( value ) ) {
828830 if ( value . length === 0 ) {
829- throw new Error ( 'Type must be provided for empty array.' ) ;
831+ throw new Error (
832+ "Parameter types must be provided for empty arrays via the 'types' field in query options."
833+ ) ;
830834 }
831835 return {
832836 type : 'ARRAY' ,
@@ -1624,6 +1628,10 @@ export class BigQuery extends common.Service {
16241628 * objects, Strings, Booleans, and Objects.
16251629 * @param {string } query.query A query string, following the BigQuery query
16261630 * syntax, of the query to execute.
1631+ * @param {object|Array<*> } query.types Provided types for query parameters.
1632+ * For positional SQL parameters, provide an array of types. For named
1633+ * SQL parameters, provide an object which maps each named parameter to
1634+ * its type.
16271635 * @param {boolean } [query.useLegacySql=false] Option to use legacy sql syntax.
16281636 * @param {object } [options] Configuration object for query results.
16291637 * @param {number } [options.maxResults] Maximum number of results to read.
@@ -1679,6 +1687,23 @@ export class BigQuery extends common.Service {
16791687 * }, function(err, rows) {});
16801688 *
16811689 * //-
1690+ * // Providing types for SQL parameters is supported.
1691+ * //-
1692+ * bigquery.query({
1693+ * query: [
1694+ * 'SELECT url',
1695+ * 'FROM `publicdata.samples.github_nested`',
1696+ * 'WHERE repository.owner = ?'
1697+ * ].join(' '),
1698+ *
1699+ * params: [
1700+ * null
1701+ * ],
1702+ *
1703+ * types: ['string']
1704+ * }, function(err, rows) {});
1705+ *
1706+ * //-
16821707 * // If you need to use a `DATE`, `DATETIME`, `TIME`, or `TIMESTAMP` type in
16831708 * // your query, see {@link BigQuery#date }, {@link BigQuery#datetime },
16841709 * // {@link BigQuery#time }, and {@link BigQuery#timestamp }.
0 commit comments