테이블 값 함수(TVF)라고도 부르는 테이블 함수는 테이블을 반환하는 사용자 정의 함수입니다. 테이블을 사용할 수 있는 어디에서나 테이블 함수를 사용할 수 있습니다. 테이블 함수는 뷰와 비슷하게 작동하지만 테이블 함수는 매개변수를 사용할 수 있습니다.
테이블 함수 만들기
테이블 함수를 만들려면 CREATE TABLE FUNCTION 문을 사용합니다. 테이블 함수에는 테이블을 생성하는 쿼리가 포함됩니다. 이 함수는 쿼리 결과를 반환합니다. 다음 테이블 함수는 INT64 매개변수를 사용하며, bigquery-public-data.usa_names.usa_1910_current라는 공개 데이터 세트에 대한 쿼리의 WHERE 절 내에서 이 값을 사용합니다.
+------+--------+-------+| year | name | total |+------+--------+-------+| 1950 | James | 86447 || 1950 | Robert | 83717 || 1950 | Linda | 80498 || 1950 | John | 79561 || 1950 | Mary | 65546 |+------+--------+-------+
테이블 함수를 루틴으로 승인할 수 있습니다.
승인된 루틴을 사용하면 결과를 생성한 기본 테이블에 대해 액세스 권한을 부여하지 않고도 특정 사용자 또는 그룹에 쿼리 결과를 공유할 수 있습니다.
예를 들어 승인된 루틴은 데이터에 대한 집계를 계산하거나 테이블 값을 조회하고 이 값을 계산에 사용할 수 있습니다.
자세한 내용은 승인된 루틴을 참조하세요.
제한사항
매개변수는 스칼라 값이어야 합니다. BigQuery의 테이블 함수는 테이블을 입력 매개변수로 사용할 수 없습니다.
쿼리 본문은 SELECT 문이어야 하며 어떤 것도 수정할 수 없습니다. 예를 들어 테이블 함수에서는 데이터 정의 언어(DDL) 및 데이터 조작 언어(DML) 문이 허용되지 않습니다. 부수적인 효과가 필요하면 대신 프로시져를 작성하는 것이 좋습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eTable functions, or table-valued functions (TVFs), are user-defined functions that return a table, usable anywhere a table is valid, and can take parameters, unlike views.\u003c/p\u003e\n"],["\u003cp\u003eTable functions are created using the \u003ccode\u003eCREATE TABLE FUNCTION\u003c/code\u003e statement, which contains a query that produces a table, and the function returns the query's result.\u003c/p\u003e\n"],["\u003cp\u003eYou can call table functions within \u003ccode\u003eSELECT\u003c/code\u003e statements, join their output with other tables, and use them in subqueries.\u003c/p\u003e\n"],["\u003cp\u003eTable functions are subject to certain limitations, such as parameters having to be scalar values, and the query body must be a \u003ccode\u003eSELECT\u003c/code\u003e statement without any modifications.\u003c/p\u003e\n"],["\u003cp\u003eTable functions are classified as a type of routine in big query, which are authorized to share query results with users without giving direct access to the underlying data.\u003c/p\u003e\n"]]],[],null,["# Table functions\n===============\n\nA table function, also called a table-valued function (TVF), is a user-defined\nfunction that returns a table. You can use a table function anywhere that you\ncan use a table. Table functions behave similarly to views, but a table function\ncan take parameters.\n\nCreate table functions\n----------------------\n\nTo create a table function, use the\n[`CREATE TABLE FUNCTION`](/bigquery/docs/reference/standard-sql/data-definition-language#create_table_function_statement)\nstatement. A table function contains a query that produces a table. The function\nreturns the query result. The following table function takes an `INT64`\nparameter and uses this value inside a `WHERE` clause in a query over a\n[public dataset](/bigquery/public-data) called\n`bigquery-public-data.usa_names.usa_1910_current`: \n\n```googlesql\nCREATE OR REPLACE TABLE FUNCTION mydataset.names_by_year(y INT64)\nAS (\n SELECT year, name, SUM(number) AS total\n FROM `bigquery-public-data.usa_names.usa_1910_current`\n WHERE year = y\n GROUP BY year, name\n);\n```\n\nTo filter in other ways, you can pass multiple parameters to a table function.\nThe following table function filters the data by year and name prefix: \n\n```googlesql\nCREATE OR REPLACE TABLE FUNCTION mydataset.names_by_year_and_prefix(\n y INT64, z STRING)\nAS (\n SELECT year, name, SUM(number) AS total\n FROM `bigquery-public-data.usa_names.usa_1910_current`\n WHERE\n year = y\n AND STARTS_WITH(name, z)\n GROUP BY year, name\n);\n```\n\n### Parameter names\n\nIf a table function parameter matches the name of a table column, it can create\nan ambiguous reference. In that case, BigQuery interprets the\nname as a reference to the table column, not the parameter. The recommended\npractice is to use parameter names that are distinct from the names of any\nreferenced table columns.\n\nUse table functions\n-------------------\n\nYou can call a table function in any context where a table is valid. The following\nexample calls the `mydataset.names_by_year` function in the `FROM` clause of\na `SELECT` statement: \n\n SELECT * FROM mydataset.names_by_year(1950)\n ORDER BY total DESC\n LIMIT 5\n\nThe results look like the following: \n\n +------+--------+-------+\n | year | name | total |\n +------+--------+-------+\n | 1950 | James | 86447 |\n | 1950 | Robert | 83717 |\n | 1950 | Linda | 80498 |\n | 1950 | John | 79561 |\n | 1950 | Mary | 65546 |\n +------+--------+-------+\n\nYou can join the output from a table function with another table: \n\n SELECT *\n FROM `bigquery-public-data.samples.shakespeare` AS s\n JOIN mydataset.names_by_year(1950) AS n\n ON n.name = s.word\n\nYou can also use a table function in a\n[subquery](/bigquery/docs/reference/standard-sql/subqueries#array_subquery_concepts): \n\n SELECT ARRAY(\n SELECT name FROM mydataset.names_by_year(1950)\n ORDER BY total DESC\n LIMIT 5)\n\nList table functions\n--------------------\n\nTable functions are a type of routine. To list all of the routines in a dataset,\nsee [List routines](/bigquery/docs/routines#list_routines).\n\nDelete table functions\n----------------------\n\nTo delete a table function, use the\n[`DROP TABLE FUNCTION`](/bigquery/docs/reference/standard-sql/data-definition-language#drop_table_function)\nstatement: \n\n DROP TABLE FUNCTION mydataset.names_by_year\n\nAuthorize routines\n------------------\n\nYou can authorize table functions as *routines* .\nAuthorized routines let you share query results with specific users or groups\nwithout giving them access to the underlying tables that generated the results.\nFor example, an authorized routine can compute an aggregation\nover data or look up a table value and use that value in a computation.\nFor more information, see [Authorized routines](/bigquery/docs/authorized-routines).\n\nLimitations\n-----------\n\n- Parameters must be scalar values. Table functions in BigQuery\n cannot take tables as input parameters.\n\n- The query body must be a `SELECT` statement and cannot modify anything. For\n example, data definition language (DDL) and data manipulation language (DML)\n statements are not allowed in table functions. If you need side-effects,\n consider writing a\n [procedure](/bigquery/docs/reference/standard-sql/data-definition-language#create_procedure)\n instead.\n\n- Table functions must be stored in the same location as the tables they\n reference.\n\nQuotas\n------\n\nFor more information about table function quotas and limits, see\n[Quotas and limits](/bigquery/quotas#table_function_limits)."]]