5

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.

1 Answer 1

9

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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