[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-17。"],[[["\u003cp\u003eLegacy SQL supports a variety of data types, including STRING, BYTES, INTEGER, FLOAT, NUMERIC, BIGNUMERIC, BOOLEAN, RECORD, TIMESTAMP, DATE, TIME, and DATETIME.\u003c/p\u003e\n"],["\u003cp\u003eLegacy SQL has limited support for NUMERIC, BIGNUMERIC, DATE, TIME, and DATETIME data types, restricting their use to non-modifying operations and specific casting functions.\u003c/p\u003e\n"],["\u003cp\u003eFor data types such as BYTES, BigQuery reads and converts Avro BYTES data, and when reading from BigQuery tables it are base64-encoded unless exported to Avro format.\u003c/p\u003e\n"],["\u003cp\u003eTIMESTAMP data can be represented as either UNIX timestamps or date and time strings, with BigQuery internally storing them as UNIX timestamps with microsecond precision.\u003c/p\u003e\n"],["\u003cp\u003eWhile legacy SQL provides these types, GoogleSQL is the preferred query syntax and offers full support for all SQL operations on DATE, DATETIME, and TIME data types.\u003c/p\u003e\n"]]],[],null,["# Legacy SQL data types\n=====================\n\n\nThis document details the data types supported by BigQuery's\nlegacy SQL query syntax. The preferred query syntax for BigQuery\nis GoogleSQL. For information on data types in GoogleSQL, see\nthe [GoogleSQL data types](/bigquery/docs/reference/standard-sql/data-types).\n\nLegacy SQL data types\n---------------------\n\nYour data can include the following data types:\n\nExact numeric in legacy SQL\n---------------------------\n\nYou can read NUMERIC or BIGNUMERIC values in non-modifying clauses such as\n`SELECT list (with aliases)`, `GROUP BY keys`, and pass-through fields in\nwindow functions, and so on. However, any computation over NUMERIC or\nBIGNUMERIC values, including comparisons, produces undefined results.\n\nThe following cast and conversion functions are supported in legacy SQL:\n\n- `CAST(\u003cnumeric\u003e AS STRING)`\n- `CAST(\u003cbignumeric\u003e AS STRING)`\n- `CAST(\u003cstring\u003e AS NUMERIC)`\n- `CAST(\u003cstring\u003e AS BIGNUMERIC)`\n\nCivil time in legacy SQL\n------------------------\n\nYou can read civil time data types---DATE, TIME, and\nDATETIME---and process them with non-modifying operators such as\n`SELECT list (with aliases)`, `GROUP BY keys`, and pass-through fields in\nwindow functions, etc. However, any other computation over civil time values,\nincluding comparisons, produces undefined results.\n\nThe following casts and conversion functions are supported in legacy SQL:\n\n- `CAST(\u003cdate\u003e AS STRING)`\n- `CAST(\u003ctime\u003e AS STRING)`\n- `CAST(\u003cdatetime\u003e AS STRING)`\n- `CAST(\u003cstring\u003e AS DATE)`\n- `CAST(\u003cstring\u003e AS TIME)`\n- `CAST(\u003cstring\u003e AS DATETIME)`\n\nIn practice, legacy SQL interprets civil time values as integers, and operations\non integers that you think are civil time values produce unexpected results.\n\nTo compute values using civil time data types, consider\n[GoogleSQL](/bigquery/sql-reference), which supports all SQL\noperations on the\n[DATE](/bigquery/sql-reference/data-types#date-type),\n[DATETIME](/bigquery/sql-reference/data-types#datetime-type), and\n[TIME](/bigquery/sql-reference/data-types#time-type) data types.\n\nWhat's next\n-----------\n\n- To set a field's data type using the API, see [`schema.fields.type`](/bigquery/docs/reference/rest/v2/tables#TableFieldSchema.FIELDS.type).\n- For GoogleSQL data types, see [data types](/bigquery/sql-reference/data-types)."]]