Arash m
Arash m

Reputation: 109

How to create table from a select query?

I've got "table1" with "id" and line geometry column ("geom_line"). I want to create "table2" whereas it's filled by select all lines which is within a polygon. I wrote following code. May anybody correct, please?

SELECT id, ST_Intersection(ST_GeomFromText('POLYGON((443425 4427680, 441353 4427680, 441368 4426075, 443762 4426149, 443425 4427680))', 32650)
, geom_line)
    FROM trajectory where geom_line IS NOT null

INTO table2 FROM mydatabase

Upvotes: 0

Views: 77

Answers (2)

Raj Kamuni
Raj Kamuni

Reputation: 388

Following is also one of the option for your requirement(Supports in MS-SQL)

SELECT ColumnName1,ColumnName1 INTO TableTest FROM Your_Table

Upvotes: 0

user330315
user330315

Reputation:

Creating a table based on a select is done using create table ... as select ... in standard SQL - and Postgres supports this as well:

create table table2
as
SELECT id, ST_Intersection(ST_GeomFromText('POLYGON((443425 4427680, 441353 4427680, 441368 4426075, 443762 4426149, 443425 4427680))', 32650)    , geom_line)
FROM trajectory 
where geom_line IS NOT null

More details as usual in the manual:
http://www.postgresql.org/docs/current/static/sql-createtableas.html

Upvotes: 3

Related Questions