Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Most programming languages have Coding styles. Some have defined standards, other have just some code of conduct that the majority of programmers follow.

Standard coding styles are have obvious benefits, in gis.stackexchange itself, it would help people better understand both questions and answers.

From some "googling", there are some reference to Coding Styles for SQL, although they are not consensual:

While this SQL coding styles can be used for Postgis, my question is if there is a Postgis\SQL coding style to handle its functions, or at least some common practices.

share|improve this question
up vote 9 down vote accepted

No, there's no style guide for PostGIS SQL, and as with other languages everyone has their own quirks, but here's my general rules, which I think lead to more readable results:

  • Use caps for SQL keywords (SELECT, INSERT, FROM, WITH, AND, OR)
  • Use mixed case for functions (ST_Distance, Abs, Strlen, ST_Intersects)
  • Prefer JOIN syntax over putting join conditions in the WHERE clause
  • Prefer WITH syntax over sub-queries

I'm sure there's some reasonable rules for writing PL/PgSQL too, but I don't do that myself.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.