Skip to main content
Question

Creating new schema in a PostGres/PostGIS databse

  • September 15, 2016
  • 5 replies
  • 80 views

jackyd
Contributor
Forum|alt.badge.img+10

Hello,

Is it possible to create a new schema in a PostGres/PostGIS database using FME?

Thanks

5 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • September 15, 2016

Hi @jackyd, yes, you can create a new schema with a SQL statement. e.g.

create schema my_schema
Where? depends on how you write features into tables belonging to the new schema. If you write features with a PostgreSQL/PostGIS writer, for example, you can set the statement to the "SQL Statement to Execute before Translation" parameter of the writer.

0684Q00000ArKRqQAN.png

Note: The execution will fail if the schema exists in the database already, but the error can be ignored if you add a hyphen to the head of the statement, like this.

-create schema my_schema

jackyd
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • September 15, 2016
takashi wrote:

Hi @jackyd, yes, you can create a new schema with a SQL statement. e.g.

create schema my_schema
Where? depends on how you write features into tables belonging to the new schema. If you write features with a PostgreSQL/PostGIS writer, for example, you can set the statement to the "SQL Statement to Execute before Translation" parameter of the writer.

0684Q00000ArKRqQAN.png

Note: The execution will fail if the schema exists in the database already, but the error can be ignored if you add a hyphen to the head of the statement, like this.

-create schema my_schema

Thank you so much @takashi this just what i need.


david_r
Evangelist
  • September 15, 2016

@takashi, I've never seen that hyphen trick, is it documented somewhere?

You can also do it like this, which may be slightly more understandable when you stumble upon it later:

CREATE SCHEMA IF NOT EXISTS schema_name

Documentation here: https://www.postgresql.org/docs/9.3/static/sql-createschema.html


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • September 15, 2016
david_r wrote:

@takashi, I've never seen that hyphen trick, is it documented somewhere?

You can also do it like this, which may be slightly more understandable when you stumble upon it later:

CREATE SCHEMA IF NOT EXISTS schema_name

Documentation here: https://www.postgresql.org/docs/9.3/static/sql-createschema.html

Hi @david_r, the hyphen trick is an FME specification that is documented in the SQLExecutor help.

 

"An individual statement may be preceded with a hyphen, indicating that errors should be ignored."

 

It's convenient in some cases.

 


david_r
Evangelist
  • September 15, 2016
takashi wrote:
Hi @david_r, the hyphen trick is an FME specification that is documented in the SQLExecutor help.

 

"An individual statement may be preceded with a hyphen, indicating that errors should be ignored."

 

It's convenient in some cases.

 

Thanks! Learnt something new today :-)

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings