{
    "content": [
        {
            "type": "text",
            "text": "# SELECT_INTO(7) (man)\n\n**Summary:** SELECTINTO - define a new table from the results of a query\n\n**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 ] [...] ]\n\n## Examples\n\n- `Create a new table filmsrecent consisting of only recent entries from the table films:`\n- `SELECT * INTO filmsrecent FROM films WHERE dateprod >= '2002-01-01';`\n\n## See Also\n\n- CREATETABLEAS(7)\n- INTO(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (16 lines)\n- **DESCRIPTION** (4 lines)\n- **PARAMETERS** (13 lines)\n- **NOTES** (10 lines)\n- **EXAMPLES** (4 lines)\n- **COMPATIBILITY** (7 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nSELECTINTO - define a new table from the results of a query\n\n### SYNOPSIS\n\n[ 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\n### DESCRIPTION\n\nSELECT 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\n### PARAMETERS\n\nTEMPORARY 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\n### NOTES\n\nCREATE 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\n### EXAMPLES\n\nCreate 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\n### COMPATIBILITY\n\nThe 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\n### SEE ALSO\n\nCREATE TABLE AS (CREATETABLEAS(7))\n\n\n\nPostgreSQL 14.23                                2026                                  SELECT INTO(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "SELECT_INTO",
        "section": "7",
        "mode": "man",
        "summary": "SELECTINTO - define a new table from the results of a query",
        "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 ] [...] ]",
        "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"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}