github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/acceptance/testdata/psql/test-psql.sh (about) 1 #!/usr/bin/env bash 2 3 set -euo pipefail 4 5 # Check that psql works in the first place. 6 psql -c "select 1" | grep "1 row" 7 8 # Check that COPY works outside of a transaction (#13395) 9 psql -d testdb <<EOF 10 CREATE DATABASE IF NOT EXISTS testdb; 11 CREATE TABLE ints (a INTEGER NOT NULL); 12 CREATE TABLE playground ( 13 equip_id integer NOT NULL, 14 type character varying(50) NOT NULL, 15 color character varying(25) NOT NULL, 16 location character varying(25), 17 install_date date, 18 ip inet 19 ); 20 21 COPY playground (equip_id, type, color, location, install_date, ip) FROM stdin; 22 1 slide blue south 2014-04-28 192.168.0.1 23 2 swing yellow northwest 2010-08-16 ffff::ffff:12 24 \. 25 EOF 26 # psql does not report failures properly in its exit code, so we check 27 # that the value was inserted explicitly. 28 psql -d testdb -c "SELECT * FROM playground" | grep blue 29 psql -d testdb -c "SELECT * FROM playground" | grep ffff::ffff:12 30 31 # Test lack of newlines at EOF with no slash-dot. 32 echo 'COPY playground (equip_id, type, color, location, install_date, ip) FROM stdin;' > import.sql 33 echo -n -e '3\trope\tgreen\teast\t2015-01-02\t192.168.0.1' >> import.sql 34 psql -d testdb < import.sql 35 psql -d testdb -c "SELECT * FROM playground" | grep green 36 psql -d testdb -c "SELECT * FROM playground" | grep 192.168.0.1 37 38 # Test lack of newlines at EOF with slash-dot. 39 echo 'COPY playground (equip_id, type, color, location, install_date, ip) FROM stdin;' > import.sql 40 echo -e '4\tsand\tbrown\twest\t2016-03-04\t192.168.0.1' >> import.sql 41 echo -n '\.' >> import.sql 42 psql -d testdb < import.sql 43 psql -d testdb -c "SELECT * FROM playground" | grep brown 44 45 # Test that the app name set in the pgwire init exchange is propagated 46 # down the session. 47 psql -d testdb -c "show application_name" | grep psql 48 49 # Test that errors in COPY FROM STDIN don't screw up the connection 50 # See #16393 51 echo 'COPY playground (equip_id, type, color, location, install_date, ip) FROM stdin;' > import.sql 52 echo -e '3\tjunk\tgreen\teast\t2015-01-02\t192.168.0.1' >> import.sql 53 echo 'garbage' >> import.sql 54 echo '\.' >> import.sql 55 echo "SELECT 'hooray'" >> import.sql 56 psql -d testdb < import.sql | grep hooray 57 # Assert the junk line wasn't added. 58 psql -d testdb -c "SELECT * from playground WHERE type='junk'" | grep "0 rows" 59 60 # Test that large COPY FROM STDIN commands don't create a bad connection status. 61 # See issue #17941. 62 echo 'COPY ints FROM stdin;' > import.sql 63 for i in {1..1000}; do 64 echo $i >> import.sql 65 done 66 echo "\." >> import.sql 67 psql -d testdb < import.sql 68 psql -d testdb -c "SELECT count(*) FROM ints" | grep "1000" 69 70 # Test that a row larger than 8192 bytes is handled OK. That's when psql splits 71 # it into multiple packets. 72 echo "Testing large row" 73 psql -d testdb -c "create table large_strings (s string)" 74 row=$(eval printf '=%.0s' {1..10000}) 75 echo 'copy large_strings from stdin;' > import.sql 76 echo $row>> import.sql 77 echo "\." >> import.sql 78 psql -d testdb < import.sql 79 psql -d testdb -c "select count(*) from large_strings" | grep "1" 80 psql -d testdb -c "select length(s) from large_strings" | grep "10000" 81 82 # Test that attempting to copy into a missing table returns the expected error 83 # to the client. It didn't use to. 84 echo 'Testing copy error' 85 output="$(psql -d testdb -c 'copy missing from stdin' 2>&1 || true)" 86 echo $output | grep 'relation "missing" does not exist' 87 88 # Test that CREATE TABLE AS returns tag CREATE TABLE AS, not CREATE (#20227). 89 psql -d testdb -c "CREATE TABLE ctas AS SELECT 1" | grep "CREATE TABLE AS"