What is Teradata's equivalent for Oracle's DUAL

前端 未结 1 583
梦毁少年i
梦毁少年i 2021-01-16 03:42

In Oracle, we can write this to generate a single row using a SELECT statement.

SELECT 1 AS x FROM dual

What is Teradata\'s eq

相关标签:
1条回答
  • 2021-01-16 04:13

    Generally, no such table is needed

    In most cases, no table is really needed in the Teradata database. The following is valid SQL (just like in H2, PostgreSQL, Redshift, SQL Server, SQLite, Sybase ASE, Sybase SQL Anywhere, Vertica)

    SELECT 1
    SELECT 1 WHERE 1 = 1
    

    Exceptions

    However, there is an exception, when a set operation is desireable. E.g. this is invalid in Teradata:

    SELECT 1 UNION ALL SELECT 2
    

    Yielding this error:

    A SELECT for a UNION,INTERSECT or MINUS must reference a table.

    But since the FROM clause is generally optional, it's very easy to emulate a DUAL table as follows:

    SELECT 1 FROM (SELECT 1 AS "DUMMY") AS "DUAL"
    UNION ALL 
    SELECT 2 FROM (SELECT 1 AS "DUMMY") AS "DUAL"
    

    Compatibility

    In case compatibility needs to be achieved with Oracle etc, it is easy to create a view that behaves like Oracle's dual:

    CREATE VIEW "DUAL" AS (SELECT 1 AS "DUMMY");
    

    Notice that DUAL is a keyword in Teradata, thus the view needs to be quoted.

    0 讨论(0)
提交回复
热议问题