{
    "mode": "man",
    "parameter": "SELECT_INTO",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/SELECT_INTO/7/json",
    "generated": "2026-05-30T05:10:03Z",
    "synopsis": "[ WITH [ RECURSIVE ] withquery [, ...] ]\nSELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]\n[ { * | expression [ [ AS ] outputname ] } [, ...] ]\nINTO [ TEMPORARY | TEMP | UNLOGGED ] [ TABLE ] newtable\n[ FROM fromitem [, ...] ]\n[ WHERE condition ]\n[ GROUP BY expression [, ...] ]\n[ HAVING condition ]\n[ WINDOW windowname AS ( windowdefinition ) [, ...] ]\n[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]\n[ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]\n[ LIMIT { count | ALL } ]\n[ OFFSET start [ ROW | ROWS ] ]\n[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]\n[ FOR { UPDATE | SHARE } [ OF tablename [, ...] ] [ NOWAIT ] [...] ]",
    "sections": {
        "NAME": {
            "content": "SELECTINTO - define a new table from the results of a query\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "[ WITH [ RECURSIVE ] withquery [, ...] ]\nSELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]\n[ { * | expression [ [ AS ] outputname ] } [, ...] ]\nINTO [ TEMPORARY | TEMP | UNLOGGED ] [ TABLE ] newtable\n[ FROM fromitem [, ...] ]\n[ WHERE condition ]\n[ GROUP BY expression [, ...] ]\n[ HAVING condition ]\n[ WINDOW windowname AS ( windowdefinition ) [, ...] ]\n[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]\n[ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]\n[ LIMIT { count | ALL } ]\n[ OFFSET start [ ROW | ROWS ] ]\n[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]\n[ FOR { UPDATE | SHARE } [ OF tablename [, ...] ] [ NOWAIT ] [...] ]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "SELECT INTO creates a new table and fills it with data computed by a query. The data is not\nreturned to the client, as it is with a normal SELECT. The new table's columns have the names\nand data types associated with the output columns of the SELECT.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "TEMPORARY or TEMP\nIf specified, the table is created as a temporary table. Refer to CREATE TABLE\n(CREATETABLE(7)) for details.\n\nUNLOGGED\nIf specified, the table is created as an unlogged table. Refer to CREATE TABLE\n(CREATETABLE(7)) for details.\n\nnewtable\nThe name (optionally schema-qualified) of the table to be created.\n\nAll other parameters are described in detail under SELECT(7).\n",
            "subsections": []
        },
        "NOTES": {
            "content": "CREATE TABLE AS is functionally similar to SELECT INTO.  CREATE TABLE AS is the recommended\nsyntax, since this form of SELECT INTO is not available in ECPG or PL/pgSQL, because they\ninterpret the INTO clause differently. Furthermore, CREATE TABLE AS offers a superset of the\nfunctionality provided by SELECT INTO.\n\nIn contrast to CREATE TABLE AS, SELECT INTO does not allow specifying properties like a\ntable's access method with USING method or the table's tablespace with TABLESPACE\ntablespacename. Use CREATE TABLE AS if necessary. Therefore, the default table access method\nis chosen for the new table. See defaulttableaccessmethod for more information.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Create a new table filmsrecent consisting of only recent entries from the table films:\n\nSELECT * INTO filmsrecent FROM films WHERE dateprod >= '2002-01-01';\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "The SQL standard uses SELECT INTO to represent selecting values into scalar variables of a\nhost program, rather than creating a new table. This indeed is the usage found in ECPG (see\nChapter 36) and PL/pgSQL (see Chapter 43). The PostgreSQL usage of SELECT INTO to represent\ntable creation is historical. Some other SQL implementations also use SELECT INTO in this way\n(but most SQL implementations support CREATE TABLE AS instead). Apart from such compatibility\nconsiderations, it is best to use CREATE TABLE AS for this purpose in new code.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "CREATE TABLE AS (CREATETABLEAS(7))\n\n\n\nPostgreSQL 14.23                                2026                                  SELECT INTO(7)",
            "subsections": []
        }
    },
    "summary": "SELECTINTO - define a new table from the results of a query",
    "flags": [],
    "examples": [
        "Create a new table filmsrecent consisting of only recent entries from the table films:",
        "SELECT * INTO filmsrecent FROM films WHERE dateprod >= '2002-01-01';"
    ],
    "see_also": [
        {
            "name": "CREATETABLEAS",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATETABLEAS/7/json"
        },
        {
            "name": "INTO",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/INTO/7/json"
        }
    ]
}