DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Introducing the MERGE Command in PostgreSQL 15
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance
  • Why SQL Server Applications Break on PostgreSQL and How Compatibility Layers Fix It
  • Fix Circular Dependencies in PostgreSQL Row-Level Security With SECURITY DEFINER Functions

Trending

  • Moving 900+ GB of Prometheus Without a Cutover Weekend
  • Taming Parameter Sniffing in SQL Server 2022 With PSP Optimization
  • Replay, Scheduling, and Throttling: Engineering a Self-Service Kafka Streaming Tool at Scale
  • Vision-Language Models in 2026: From Research Breakthroughs to Cloud-Native Production Systems

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. PostgreSQL's psql \set vs. SET

PostgreSQL's psql \set vs. SET

How do we differentiate between \set and SET?

By 
Dustin Marx
·
Feb. 28, 19 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
15.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

It is easy for someone who is new to PostgreSQL and who uses PostgreSQL's terminal editor psql to confuse the commands\set and SET. This post contrasts these commands and provides a brief overview of other commands that include the word "set."

The easiest way to remember how to differentiate \set from SET is to keep in mind that the "backslash commands" such as \set are "meta commands" for the command-line psql tool and do not mean anything to the PostgreSQL database itself. The SET command, which lacks a backslash, is a PostgreSQL database command that happens to be executed against the database from the psql command-line client.

Image title

There are two more psql meta commands that "set" things and include the name "set." The \pset met command configures how psql presents "query result tables." Like \set, \pset can be specified without argument to see all of the current presentation settings.

Unlike the psql metacommands, \set and \pset, the \gset psql metacommand does affect the PostgreSQL server because \gset submits the query buffer to the server and then stores the output returned from the server into specified psql variables. I discussed \gset with a few additional details in the blog post "Setting PostgreSQL psql Variable Based Upon Query Result."

Although \set and SET can be used to set variables, the easiest way to distinguish between them is to consider that the backslash commands such as \set are psql commands (and so \pset sets variables in the psql client tool) and commands without the backslash such as SET are PostgreSQL commands sent to the server from psql or from any other client (but ultimately set variables on the server).

Let us know your thoughts in the comments down below.

PostgreSQL Command (computing)

Published at DZone with permission of Dustin Marx. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Introducing the MERGE Command in PostgreSQL 15
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance
  • Why SQL Server Applications Break on PostgreSQL and How Compatibility Layers Fix It
  • Fix Circular Dependencies in PostgreSQL Row-Level Security With SECURITY DEFINER Functions

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook