Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

1 Answer 1

up vote 8 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

 
discard

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.