Menu
CoddyTech

Comments and Statements

Part of the First Queries section of Coddy's PostgreSQL journey. Lesson 3 of 20.

A comment explains a query without becoming part of its result. PostgreSQL ignores text from -- to the end of a line. A semicolon ends a statement, so a script can contain more than one statement.

Input table products:

idnamecategorypricestockactivenote
1Maptravel125TrueNULL
2Notebookbooks80TrueRecycled
3Atlasbooks243FalseNULL
4Mughome128TrueBlue
5lamphome302FalseClearance
6Mini maptravel610TrueNULL
-- Read the catalog
SELECT category FROM products;

The comment is skipped and the query returns categories. In this editor, when several statements run, the final statement supplies the result table. Keep the query you want checked last.

Use -- for a line comment. End each statement with ; and leave the required result query last.

challenge icon

Challenge

Easy

Write a line comment describing a stock check, then return name and price for all products. Row order does not matter.

The input tables are shown in the test panel. Each run starts from fresh data. Return the named columns in the stated order; do not hard-code the displayed rows.

Try it yourself

-- Write your SQL here.
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in First Queries

Practice on your own: PostgreSQL playground