Skip to main content
Question

Creating new schema in a PostGres/PostGIS databse

  • September 15, 2016
  • 5 replies
  • 96 views

jackyd
Supporter
Forum|alt.badge.img+16

Hello,

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

Thanks

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

takashi
Celebrity
  • 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
Supporter
Forum|alt.badge.img+16
  • Author
  • Supporter
  • 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

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


david_r
Celebrity
  • 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
Celebrity
  • 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

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
Celebrity
  • September 15, 2016
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 :-)