Comment

Comment by rarrrrrr

psql also allows you to set local variables and interpolate them into SQL. Values can be assigned from query results or with shell style back ticks! Powerful and frightening!

From the manual:

  => SELECT 'hello' AS var1, 10 AS var2
  -> \gset
  => \echo :var1 :var2
  hello 10

  testdb=> \set content `cat my_file.txt`
  testdb=> INSERT INTO my_table VALUES (:'content');
parent rarrrrrr 6 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton