psql

Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib

允我心安 提交于 2019-12-28 03:21:06
问题 I just installed posgresql with homebrew and when I go on to type the command psql I get the following error: dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib Referenced from: /usr/local/bin/psql Reason: image not found [1] 69711 trace trap psql Does anyone have any idea about what's wrong? 回答1: I was getting the exact same error, but the above answers didn't work for me. I had to reinstall postgresql. brew reinstall postgresql 回答2: The key problem is that your

PostgreSQL epoch time conversion

三世轮回 提交于 2019-12-25 14:13:23
问题 I am using the postgresSQL function to_timestamp(double precision) to convert from epoch time to normal timestamp but I am facing a problem where the timestamp is incorrect SELECT to_timestamp(1428058548491); produces "47223-05-17 12:08:11.000064+02" while it should be 4/3/2015, 12:55:48 PM GMT+2:00 DST SELCT to_timestamp(1428058557697); produces "47223-05-17 14:41:36.999936+02" while it should be 4/3/2015, 12:55:57 as can be seen the dates have been converted totally incorrect 回答1: As was

SQL Create view statement using WITH keyword

我的梦境 提交于 2019-12-25 09:09:09
问题 I am having issues writing this Create view statement in SQL. I want to get personID, first name, and last name from a table for people that go to the University of Colorado (uid = 2). Then I want to use the WITH clause to combine this table with my body_composition table and print out everything in the body_composition table as well. Here is the exact definition of the query I am making. First, write a query that returns the person’s id (pid), first name (fname) and last name (lname) from

How to find the proportion of zones for each neighbourhood using psql?

爱⌒轻易说出口 提交于 2019-12-25 07:18:51
问题 I have a table with Neighbourhood, Zones and Lot size. How to find the proportion of zones in Each neighbourhood using Lot size ?? This is my table: Neighbourhood Zones Lotsize Albany RSL 415 Albany RSL 410 Albany PU 34621 Abbottsfield RF5 24267 Abbottsfield AP 9745 Abbottsfield CSC 57799 回答1: This should work: SELECT p.Neighbourhood, p.Zones, (CAST(COUNT(p.*) AS FLOAT) / CAST( (SELECT COUNT(*) FROM properties AS p1 WHERE p1.Neighbourhood=p.Neighbourhood) AS FLOAT) ) AS proportion FROM

Greenplum to file using PSQL

我们两清 提交于 2019-12-25 07:12:04
问题 I'm trying to export data from Green-plum to a text file(client) with pipe delimiter using PSQL and \copy. In the output i see single slash is converted to double slash and tab is converted \t. Example N\A is converted to N\\A So how to get just N\A instead N\\A and just spaces instead of \t ? Note: i`m allowed to use only \copy. Since my file is huge im getting space issue while use SED or Perl for find and replace 回答1: Assuming you don't have any "^" characters, you could use that as the

Pass command line args to sql (Postgres)

流过昼夜 提交于 2019-12-25 00:53:13
问题 How can I pass command line args to sql files ran with psql (Postgres)? i.e. psql mydatabase < mysqlfile.sql arg1 arg2 arg3... Is this possible? 回答1: Use variable interpolation feature in psql. If you specify -v variable1=value1 or --set variable1=value1 parameter on command line, then :variable1 in the sql file will be replaced with corresponding text value. Note: use standard-SQL quoted strings if you need quotes, spaces and so on. Example: echo "SELECT :arg1 FROM :arg2 LIMIT 10;" > script

PSQL Error Level in Batch For Loop

不打扰是莪最后的温柔 提交于 2019-12-24 15:01:07
问题 I am attempting to run a postgres query from within a batch file. However, I have thus far been unable to detect when the command fails. The following is what I have tried thus far: @FOR /F %%A IN ('PSQL -U userName -d dbName -t -c "SELECT * FROM nonExistantTable" 2^>^&1') DO @( ECHO !ERRORLEVEL! ) I have also tried the following: 1) Adding "CALL" prior to the sql command ( CALL PSQL -U ... ) 2) Adding "-v ON_ERROR_STOP=1" to the sql command, both with and without the "CALL" command ( PSQL -U

postgresql equivalent to $mysqli->insert_id

跟風遠走 提交于 2019-12-24 14:19:16
问题 Is there an equivalent to $mysqli->insert_id in postgresql 9.3? I am importing into one table, but I need to take the last primary key created in the table and apply it as a foreign key in the second table? Table 1 ----> Table 2 to complete a record. A bit more info: $sql = "INSERT INTO sheet_tbl (site_id, eventdate) VALUES ('$_POST[site_id]','$_POST[eventdate]') returning id"; **Using the sql above, i insert my record, how would I then utilise this in my next SQL insert, If i use returning

How do I run an SQL file in PostgreSQL using a Linux terminal?

血红的双手。 提交于 2019-12-24 06:50:02
问题 I am working as a software tester. I want to to test my project locally. So I want to insert the database using the psql command. I tried so many times. I couldn't get to access the login page. This is what I did: postgres@naveen-Inspiron-3542:/home/naveen$ psql -U admin docmgr Password for user admin: psql (9.5.4) Type "help" for help. docmgr=> psql docmgr -f /var/www/html/docmgr/application/assets/dd/structs/docmgr_21Oct2016.sql -U admin docmgr-> \dt No relations found. docmgr-> \dt No

How to use \copy in postgresql with pgadmin4

主宰稳场 提交于 2019-12-23 19:08:08
问题 I want to use the \copy command to make csv file with relative path. I used a query to make from test table to csv file named test.csv \copy (SELECT * FROM test) to './test.csv' with csv But in postgresql pgadmin4, it shows that \copy command as a syntax error (there is an underline under the word '\copy') and shows a message like below. ERROR: syntax error at or near "/" LINE 2: /copy (SELECT * FROM test) to './persons_client.csv' with cs... ^ ********** Error ********** ERROR: syntax error