Writing SQL Statements

Every SQL document contains the Text view with SQL editor in it. You switch to this view to edit your SQL queries.

When you type text in SQL editor, it automatically recognizes and highlights SQL syntax.

For ease of SQL writing and reviewing, you can also use such supported shortcut keys as:

  • CTRL+PLUS (+) KEY to zoom the query in
  • CTRL+MINUS (-) KEY to zoom the query out
  • CTRL+0 to return an SQL document to the one-to-one scale

You write and execute SQL queries not only one at a time but you may as well compose SQL scripts. SQL scripts consist of multiple SQL statements separated by the appropriate statement delimiter.

If you are using more than one language in your query, it is important to specify it in between two $ signs. This will help the parser to correctly identify it, as well as find the beginning and end of the procedure/function body. For example:

CREATE PROCEDURE insert_data(a integer, b integer)
LANGUAGE SQL
AS $sql$
    INSERT INTO table VALUES (a);
   INSERT INTO table VALUES (b);
$sql$;

CREATE FUNCTION public.function_name()
    RETURNS INT
LANGUAGE plpgsql
AS $plpgsql$
BEGIN
    RETURN NULL;
END;
$plpgsql$

$plpgsql$, $sql$ are not stored in a database but help dbForge Studio determine the language when reading an object from it. Therefore, you will not violate the compatibility of the code with other IDEs for PG by specifying the language.

Note

The procedure or function will also work correctly in PostgreSQL if you simply specify $$. dbForge Studio will highlight the entire body as a string. IntelliSense and code formatter will not work in this part of the query:

PostgreSQL language example

Working with comments

When writing SQL code, it is essential to include comments to enhance its readability and understandability for other developers who might need to work with it later.

Comment out the selected lines

To leave a comment in the SQL document:

  1. Select the lines you would like to comment out.
  2. On the Text Editor toolbar, click the Comment out the selected lines button or press Ctrl+K, C.

Customize TODO comments

Colorize the TODO comments, making them visually distinct from regular ones. In order to customize these comments:

  1. Go to the Tools menu and select Options.
  2. In the Options window, expand the Environment category.
  3. Select Fonts and Colors.
  4. Set the desired font, size, and color for the TODO comments.
  5. Click OK once done.

TODO comments customization

Uncomment the selected lines

To remove comment characters from the SQL document:

  1. Select the lines you would like to remove the comment from.
  2. On the Text Editor toolbar, click the Uncomment the selected lines button or press Ctrl+K, U.

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for PostgreSQL.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for PostgreSQL?