File: psql.sql

package info (click to toggle)
postgresql-plsh 1.20171014-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 264 kB
  • sloc: ansic: 562; sql: 136; makefile: 40; sh: 13
file content (15 lines) | stat: -rw-r--r-- 296 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CREATE TABLE pbar (a int, b text);
INSERT INTO pbar VALUES (1, 'one'), (2, 'two');

CREATE FUNCTION query (x int) RETURNS text
LANGUAGE plsh
AS $$
#!/bin/sh
if which psql >/dev/null; then
    psql -X -At -c "select b from pbar where a = $1"
else
    echo 'no PATH?' 1>&2
fi
$$;

SELECT query(1);