![]() To verify the table creation, you can query data from the action_film table: SELECT * FROM action_film CREATE TABLE action_film AS SELECTĬode language: SQL (Structured Query Language) ( sql ) The following statement creates a table that contains action films that belong to category one. We will use the film and film_category table from the sample database for the demonstration. In case you want to avoid an error by creating a new table that already exists, you can use the IF NOT EXISTS option as follows: CREATE TABLE IF NOT EXISTS new_table_nameĪS query Code language: SQL (Structured Query Language) ( sql ) PostgreSQL CREATE TABLE AS statement examples If you want the table columns to have different names, you can specify the new table columns after the new table name: CREATE TABLE new_table_name ( column_name_list) The columns of the new table will have the names and data types associated with the output columns of the SELECT clause. The UNLOGGED keyword allows the new table to be created as an unlogged table: CREATE UNLOGGED TABLE new_table_name The TEMPORARY or TEMP keyword allows you to to create a temporary table: CREATE TEMP TABLE new_table_name Second, provide a query whose result set is added to the new table after the AS keyword.First, specify the new table name after the CREATE TABLE clause.The following shows the syntax of the CREATE TABLE AS statement: CREATE TABLE new_table_nameĪS query Code language: SQL (Structured Query Language) ( sql ) The CREATE TABLE AS statement creates a new table and fills it with the data returned by a query. ![]() Introduction to the PostgreSQL CREATE TABLE statement ![]() Summary: in this tutorial, you will learn how to use the PostgreSQL CREATE TABLE AS statement to create a new table from the result set of a query. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |