psql

Defining multi-line strings in psql

懵懂的女人 提交于 2020-08-24 05:58:56
问题 I would like to paste 123 456 789 into psql and to store multi-line string in some variable (ie. :str ) for later use. Is that possible? Now I'm getting unterminated quoted string error. 回答1: A little clunky, but in version 9.3 and up, you can do it with \gset in conjunction with a dollar-quoted literal: SELECT $$123 456 789$$ AS str \gset 来源: https://stackoverflow.com/questions/31454108/defining-multi-line-strings-in-psql

Password authentication failed error on running laravel migration

南楼画角 提交于 2020-08-09 08:19:44
问题 I am trying to deploy my Laravel app on a DigitalOcean droplet. The droplet is setup with nginx, php7, and postgres, I follow up the tuts from DigitalOcean on how to set them up. Then I try to follow this tutorial on how to deploy the Laravel app using the git hook and so on. Now the app itself is up and running, I can access the pages and all. But I can't run php artisan migrate . I have been changing the database username, name, password on .env file, but I always get the exact same error:

Show all results in postgresql?

a 夏天 提交于 2020-07-31 04:44:25
问题 My postgres windows client, upon receiving a query with many results, only shows some of them initially, showing -- More -- at the bottom and making you hit "enter" to show each new result line. This is cumbersome and silly. What can I do to make it show me absolutely every result from the start? 回答1: Assuming you mean psql with "my postgres windows client", you can turn off the use of the pager using the \pset command: \pset pager off If you want to permanently turn the pager off, add that

How to execute psql interactive in its docker container?

笑着哭i 提交于 2020-07-09 13:41:41
问题 I want to run a query in Postgres interactive shell. I'm using a docker container for this purpose as the following: Here is the relevant piece of docker-compose: db_of_ivms: image: postgres:10 restart: unless-stopped ports: - 5432:5432 container_name: db_of_ivms environment: POSTGRES_PASSWORD: xxx POSTGRES_USER: ivms_usr POSTGRES_DB: ivms_db Nevertheless, I'm dealing with this error: docker exec -it -u 0 db_of_ivms bash # psql psql: FATAL: role "root" does not exist 回答1: You need shell in

psql “more is not recognized” error

a 夏天 提交于 2020-07-09 03:54:41
问题 I am using the postgresql (9.4) interactive terminal psql on Windows 8.1 (64 bit). After installing and creating a database and table and inserting data into a row I want to view the data. However, when I type SELECT * FROM my_table; I get an error: 'more' is not recognized as an internal or external command, operable program or batch file. After adding "C:\Windows\System32;" to my path variable, more works in Powershell (e.g. more hello.txt) but still not in psql. What else do I need to do

creating pg_cron extension within docker-entrypoint-initdb.d fails

試著忘記壹切 提交于 2020-06-28 01:56:31
问题 If I create the pg_cron extension in a docker-entrypoint-initdb.d/init.sql file, the docker image fails to run and docker logs <id> just says "No such container." Here's the relevant .sql snippet: CREATE DATABASE my_database; \c my_database; CREATE EXTENSION IF NOT EXISTS postgis CASCADE; CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; CREATE EXTENSION IF NOT EXISTS pg_cron CASCADE; However, if I create the pg_cron extension after the docker run command completes (i.e. remove the last

creating pg_cron extension within docker-entrypoint-initdb.d fails

蓝咒 提交于 2020-06-28 01:54:43
问题 If I create the pg_cron extension in a docker-entrypoint-initdb.d/init.sql file, the docker image fails to run and docker logs <id> just says "No such container." Here's the relevant .sql snippet: CREATE DATABASE my_database; \c my_database; CREATE EXTENSION IF NOT EXISTS postgis CASCADE; CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; CREATE EXTENSION IF NOT EXISTS pg_cron CASCADE; However, if I create the pg_cron extension after the docker run command completes (i.e. remove the last

Using \COPY to load CSV with JSON fields into Postgres

天大地大妈咪最大 提交于 2020-06-25 18:12:57
问题 I'm attempting to load TSV data from a file into a Postgres table using the \COPY command. Here's an example data row: 2017-11-22 23:00:00 "{\"id\":123,\"class\":101,\"level\":3}" Here's the psql command I'm using: \COPY bogus.test_table (timestamp, sample_json) FROM '/local/file.txt' DELIMITER E'\t' Here's the error I'm receiving: ERROR: invalid input syntax for type json DETAIL: Token "sample_json" is invalid. CONTEXT: JSON data, line 1: "{"sample_json... COPY test_table, line 1, column

Using \COPY to load CSV with JSON fields into Postgres

こ雲淡風輕ζ 提交于 2020-06-25 18:10:31
问题 I'm attempting to load TSV data from a file into a Postgres table using the \COPY command. Here's an example data row: 2017-11-22 23:00:00 "{\"id\":123,\"class\":101,\"level\":3}" Here's the psql command I'm using: \COPY bogus.test_table (timestamp, sample_json) FROM '/local/file.txt' DELIMITER E'\t' Here's the error I'm receiving: ERROR: invalid input syntax for type json DETAIL: Token "sample_json" is invalid. CONTEXT: JSON data, line 1: "{"sample_json... COPY test_table, line 1, column

Using \COPY to load CSV with JSON fields into Postgres

回眸只為那壹抹淺笑 提交于 2020-06-25 18:10:01
问题 I'm attempting to load TSV data from a file into a Postgres table using the \COPY command. Here's an example data row: 2017-11-22 23:00:00 "{\"id\":123,\"class\":101,\"level\":3}" Here's the psql command I'm using: \COPY bogus.test_table (timestamp, sample_json) FROM '/local/file.txt' DELIMITER E'\t' Here's the error I'm receiving: ERROR: invalid input syntax for type json DETAIL: Token "sample_json" is invalid. CONTEXT: JSON data, line 1: "{"sample_json... COPY test_table, line 1, column