Let's say we want to create a table named " author_info" with the same columns and data as " author_details". We have already created a table named “author_details” that has the following structure: SELECT * FROM author_details Note: If the user wants a table with a different name, they can specify different table columns after the new table name.Įxample 1: How Do I Create a Table via CREATE TABLE AS Statement? WHERE is an optional clause used to specify a specific condition/criteria. Col_list represents the existing table's columns based on which a new table will be defined/created. In the above snippet, new_tab represents the table name to be created. Follow the below syntax to avail the functionality of the Postgres’ CREATE TABLE AS statement: CREATE TABLE new_tab AS It creates the table based on the result-set retrieved by the SELECT query. In Postgres, the CREATE TABLE AS statement allows us to create a table from an existing one. How Do I Create a Table Via CREATE TABLE AS SELECT Statement in Postgres? How to Avoid Table Already Existing Error in Postgres?.How to Create an UNLOGGED Table Via the CREATE TABLE AS SELECT Command in Postgres?.How to Create a TEMPORARY Table Via the CREATE TABLE AS SELECT Command in Postgres?.How Do I Create a Table Via the CREATE TABLE AS SELECT Statement in Postgres?. For this purpose, the following content will be covered in this write-up: This blog post will consider various examples to demonstrate the working of the CREATE TABLE AS statement in Postgres. The newly created table will have the same table structure (e.g., column names, data types, etc.) as the columns in the SELECT query. Postgres allows us to create a table via the SELECT command for this purpose, the CREATE TABLE statement is used along with an AS clause followed by a SELECT statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |