Skip to main content
deleted 4 characters in body
Source Link
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

Use \gset in psql to store the result of a query in a local variable - like dezso already advised. Shorter yet, \gset can replace the semicolon (;) as query terminator:

test=# SELECT count(*) AS list FROM department.master_data \gset

Then, to get a single-quoted string (with any contained single quotes safely escaped automatically) refer to the psql variable with this syntax variant: :'list'. Note the enclosing '' after the colon! So:

test=# COMMENT ON TABLE department.master_data IS :'list';

Read about SQL interpolation in the manual.

Related:

Use \gset in psql to store the result of a query in a local variable - like dezso already advised. Shorter yet, \gset can replace the semicolon (;) as query terminator:

test=# SELECT count(*) AS list FROM department.master_data \gset

Then, to get a single-quoted string (with any contained single quotes safely escaped automatically) refer to the psql variable with this syntax variant: :'list'. Note the enclosing '' after the colon! So:

test=# COMMENT ON TABLE department.master_data IS :'list';

Read about SQL interpolation in the manual.

Related:

Use \gset in psql to store the result of a query in a local variable - like dezso already advised. Shorter yet, \gset can replace the semicolon (;) as query terminator:

test=# SELECT count(*) AS list FROM department.master_data \gset

Then, to get a single-quoted string (with any contained single quotes safely escaped automatically) refer to the psql variable with this syntax variant: :'list'. Note the enclosing '' after the colon!

test=# COMMENT ON TABLE department.master_data IS :'list';

Read about SQL interpolation in the manual.

Related:

added 18 characters in body
Source Link
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

Use \gset in psql to store the result of a query in a local variable - like dezso already advised. Shorter yet, \gset can replace the semicolon (;) as query terminator:

test=# SELECT count(*) AS list FROM department.master_data \gset

Then, to get a single-quoted string (with any contained single quotes safely escaped automatically) refer to the psql variable with this syntax variant: :'list'. Note the enclosing '' after the colon! So:

test=# COMMENT ON TABLE department.master_data IS :'list';

Read about SQL interpolation in the manual.

Related:

Use \gset in psql to store the result of a query in a local variable - like dezso already advised. Shorter yet, \gset can replace the semicolon (;) as query terminator:

test=# SELECT count(*) AS list FROM department.master_data \gset

Then, to get a single-quoted string (with any contained single quotes safely escaped automatically) refer to the psql variable with this syntax variant: :'list'. Note the enclosing ''! So:

test=# COMMENT ON TABLE department.master_data IS :'list';

Read about SQL interpolation in the manual.

Use \gset in psql to store the result of a query in a local variable - like dezso already advised. Shorter yet, \gset can replace the semicolon (;) as query terminator:

test=# SELECT count(*) AS list FROM department.master_data \gset

Then, to get a single-quoted string (with any contained single quotes safely escaped automatically) refer to the psql variable with this syntax variant: :'list'. Note the enclosing '' after the colon! So:

test=# COMMENT ON TABLE department.master_data IS :'list';

Read about SQL interpolation in the manual.

Related:

Source Link
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

Use \gset in psql to store the result of a query in a local variable - like dezso already advised. Shorter yet, \gset can replace the semicolon (;) as query terminator:

test=# SELECT count(*) AS list FROM department.master_data \gset

Then, to get a single-quoted string (with any contained single quotes safely escaped automatically) refer to the psql variable with this syntax variant: :'list'. Note the enclosing ''! So:

test=# COMMENT ON TABLE department.master_data IS :'list';

Read about SQL interpolation in the manual.