Skip to content

Table Value Function en

谷深 edited this page Dec 16, 2022 · 1 revision

Description

Havenask supports table-valued functions (TVFs).
In a SQL statement, you can use a TVF to perform an operation on a table. The inputs of a TVF include one or more scalar parameters and a SQL statement that specifies a table. The output of a TVF is a table.

Syntax

SELECT:

  SELECT [ DISTINCT ]

    { * | projectItem [, projectItem ]* }

  FROM Table({TVF})

    [ WHERE booleanExpression ]

    [ GROUP BY { groupItem [, groupItem ]* } ]

    [ ORDER BY { orderByItem [, OrderByItem ]* }]

    [ HAVING booleanExpression ]

    [ LIMIT number]

    [ OFFSET number]



TVF:

	{TVF Name}({scalar parameter}*, {SELECT})

Examples

Specify a single TVF in a statement

SELECT

    *

FROM

    TABLE (

        one_part_tvf(

            'rtp_url',

            123,

            (

                SELECT i1, i2, d3, d4 FROM t1

            )

        )

    )

Specify multiple nested TVFs in a statement

You cannot specify nested TVFs in the following format:

SELECT

    *

from

    TABLE (

        tvf1(

            tvf2(

                (

                    select

                        *

                    from

                        t1

                )

            )

        )

    )

You can specify nested TVFs in the following format:

SELECT

    *

FROM

    TABLE (

        one_part_tvf_enable_shuffle(

            'rtp_url',

            123,

            (

                SELECT

                    i1, i2

                FROM

                    TABLE (

                        one_part_tvf_enable_shuffle(

                            'rtp_url_2',

                            234,

                            (

                                SELECT i1, i2, d3, d4 FROM t1

                            )

                        )

                    )

            )

        )

    )

Built-in TVFs

View

Clone this wiki locally