psql

how to set up the psql command in cygwin?

本秂侑毒 提交于 2019-12-02 20:56:28
I have a local dev site on my machine with Apache server and PostgreSQL 9.1 database. As I'm using Windows, I also installed Cygwin. I want to access to database and make some queries via Cygwin insead of pgAdmin III, but it tells me that psql command not found. How should I set up the psql command in cygwin? As of today, you just have to install postgresql-client package in cygwin: Run your cygwin setup.exe file (this can be run multiple times to add more packages). Type postgresql into the search box, select postgresql-client and press "next" to install. Now you can open Cygwin terminal and

PostgreSQL user listing

耗尽温柔 提交于 2019-12-02 16:11:51
I want to get a list of users for a certain database in psql - for example "template0". Who are the users? Or for "template1" database: - who are the users there? Already tried: \du+ -- no database is Listed not Users Select * from "pg_users"; -- no database is listed User aren't actually, "for the database", they're for cluster and are given different permissions to access databases. To list users \du should do, but you need to be connected. Something like psql template1 -c '\du' from the command line prompt should do. (or \du from psql prompt when you are connected to the database ). You

postgresql extracting function source

坚强是说给别人听的谎言 提交于 2019-12-02 04:38:59
Need to extract the source of a PostgreSQL function using SQL. I am seeing this odd behavior with one of the function, all other functions (around 200+ ) work absolutely fine. When I run the following statement, it works: select prosrc from pg_proc where proname= 'accounts_count'; However when I run the following, it returns an empty string: select routine_definition from information_schema.routines where specific_name = 'accounts_count_66243' PostgreSQL version 8.3. I have tried using both pgAdmin III and psql. Not a show stopper, but would be useful to know why this might be. Any ideas

Selecting floating point numbers in decimal form

天涯浪子 提交于 2019-12-01 23:58:13
问题 I've a small number in a PostgreSQL table: test=# CREATE TABLE test (r real); CREATE TABLE test=# INSERT INTO test VALUES (0.00000000000000000000000000000000000000000009); INSERT 0 1 When I run the following query it returns the number as 8.96831e-44 : test=# SELECT * FROM test; r ------------- 8.96831e-44 (1 row) How can I show the value in psql in its decimal form ( 0.00000000000000000000000000000000000000000009 ) instead of the scientific notation? I'd be happy with 0

Selecting floating point numbers in decimal form

心已入冬 提交于 2019-12-01 21:40:36
I've a small number in a PostgreSQL table: test=# CREATE TABLE test (r real); CREATE TABLE test=# INSERT INTO test VALUES (0.00000000000000000000000000000000000000000009); INSERT 0 1 When I run the following query it returns the number as 8.96831e-44 : test=# SELECT * FROM test; r ------------- 8.96831e-44 (1 row) How can I show the value in psql in its decimal form ( 0.00000000000000000000000000000000000000000009 ) instead of the scientific notation? I'd be happy with 0.0000000000000000000000000000000000000000000896831 too. Unfortunately I can't change the table and I don't really care about

Use variable set by psql meta-command inside of DO block

大兔子大兔子 提交于 2019-12-01 21:35:39
Here's what I would like to do: \set values foo,bar,baz DO $$ DECLARE value TEXT; values TEXT[] := string_to_array(:'values', ','); BEGIN FOREACH value IN ARRAY values LOOP raise notice 'v: %', value; END LOOP; END $$ LANGUAGE plpgsql; Which results in the following error: ERROR: syntax error at or near ":" SELECT string_to_array(:'values', ',') INTO values... ^ Here's the solution I have currently, but it feels hacky: \set values foo,bar,baz PREPARE get_values AS SELECT string_to_array(:'values', ','); DO $$ DECLARE value TEXT; values TEXT[]; BEGIN EXECUTE 'EXECUTE get_values' INTO values;

Unable to restore psql database from pg_dump with a different username

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 18:38:30
I need to dump a postgres database from computer1 with postgres username1 and then restore it on computer2 with postgres username2. I keep running into the error that looks like the backup file wants to use username1: When I run this on computer2: psql dbname < backupname.pgsql I get this error: ERROR: role "username1" does not exist I have tried: // Dumping from computer1: pg_dump dbname > backupname.sql pg_dump dbname > backupname.pgsql pg_dump -U username1 dbname -N topology -T spacial_ref_sys > backupname.pgsql // Restoring on computer2: psql dbname < backupname.pgsql Is it the dumping or

Postgresql - is there a way to disable the display of INSERT statements when reading in from a file? [closed]

只谈情不闲聊 提交于 2019-12-01 18:12:38
I populate a postgresql database from a file. I get a lot of: INSERT 0 1 statements. Is there a way to not display these commands at all? They scroll away earlier output on my shell right now and do not yield a lot of useful information (what does INSERT 0 1 mean? is that like saying "yo dude the insert command was a success"?). It seems I get one INSERT 0 1 line for every INSERT statement in that .sql file I read from and this is a massive file. The psql manual says: -q --quiet Specifies that psql should do its work quietly. By default, it prints welcome messages and various informational

Postgresql - is there a way to disable the display of INSERT statements when reading in from a file? [closed]

主宰稳场 提交于 2019-12-01 17:57:39
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I populate a postgresql database from a file. I get a lot of: INSERT 0 1 statements. Is there a way to not display these commands at all? They scroll away earlier output on my shell right now and do not yield a lot of useful information (what does INSERT 0 1 mean? is that like saying "yo dude the insert command

psql: permission denied for database “dbname” (“User does not have CONNECT privilege.”) / “unrecognized role option 'connect'”

拟墨画扇 提交于 2019-12-01 03:32:06
when I try to login to my database with psql, doing this: psql dbname --username=qgis --password >>(prompts for password, entered password) psql: FATAL: permission denied for database "gisdatabase" DETAIL: User does not have CONNECT privilege. I've searched around on Google for information on this simple issue but haven't found anyone directly talking about this. I've tried doing this: psql dbname >>ALTER ROLE qgis WITH CONNECT; But got this error: ERROR: unrecognized role option "connect" So once again, here I am, asking yet another question on stackoverflow. Thanks for your time folks You