psql

Find the host name and port using PSQL commands

二次信任 提交于 2019-11-27 05:03:24
问题 I have PSQL running, and am trying to get a perl application connecting to the database. Is there a command to find the current port and host that the database is running on? 回答1: The default PostgreSQL port is 5432 . The host that the database is operating on should have been provided by your hosting provider; I'd guess it would be the same host as the web server if one wasn't specified. Typically this would be configured as localhost, assuming your web server and database server are on the

The Response content must be a string or object implementing __toString(), “boolean” given after move to psql

独自空忆成欢 提交于 2019-11-27 02:33:30
问题 As soon as I move my Laravel App from MySQL to pSQL. I kept getting this error. The Response content must be a string or object implementing __toString(), "boolean" given. I have an API that suppose to return my promotion http://localhost:8888/api/promotion/1 public function id($id){ $promotion = Promotion::find($id); dd($promotion); //I got something here return $promotion; } It used to return my promotion, now it return an error. dd($promotion); I got Promotion {#410 ▼ #table: "promotions"

psql: FATAL: database “<user>” does not exist

泪湿孤枕 提交于 2019-11-27 02:20:13
I'm using the PostgreSql app for mac ( http://postgresapp.com/ ). I've used it in the past on other machines but it's giving me some trouble when installing on my macbook. I've installed the application and I ran: psql -h localhost It returns: psql: FATAL: database "<user>" does not exist It seems I can't even run the console to create the database that it's attempting to find. The same thing happens when I just run: psql or if I launch psql from the application drop down menu: Machine stats: OSX 10.8.4 psql (PostgreSQL) 9.2.4 Any help is appreciated. I've also attempted to install PostgreSql

dynamic sql query in postgres

独自空忆成欢 提交于 2019-11-27 02:03:58
I was attempting to use Dynamic SQL to run some queries in postgres. Example: EXECUTE format('SELECT * from result_%s_table', quote_ident((select id from ids where condition = some_condition))) I have to query a table, which is of the form result_%s_table wherein, I need to substitute the correct table name (an id) from an another table. I get the error ERROR: prepared statement "format" does not exist Link: string substitution with query result postgresql Craig Ringer EXECUTE ... USING only works in PL/PgSQL - ie within functions or DO blocks written in the PL/PgSQL language. It does not work

Postgres JSON data type Rails query

萝らか妹 提交于 2019-11-26 23:47:32
I am using Postgres' json data type but want to do a query/ordering with data that is nested within the json. I want to order or query with .where on the json data type. For example, I want to query for users that have a follower count > 500 or I want to order by follower or following count. Thanks! Example: model User data: { "photos"=>[ {"type"=>"facebook", "type_id"=>"facebook", "type_name"=>"Facebook", "url"=>"facebook.com"} ], "social_profiles"=>[ {"type"=>"vimeo", "type_id"=>"vimeo", "type_name"=>"Vimeo", "url"=>"http://vimeo.com/", "username"=>"v", "id"=>"1"}, {"bio"=>"I am not a person

PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “M”

做~自己de王妃 提交于 2019-11-26 23:33:24
问题 So I have a gender column on my user model and it's currently a string, I'd like to change it to a integer and make Male '1', and Female '0' as it's presently Male "M" Female "F". When running this migration: class ChangeGenderToIntegerOnUser < ActiveRecord::Migration def change change_column :users, :gender, 'integer USING CAST(gender AS integer)' end end I get the following error: error message: PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "M" : ALTER TABLE "users

“psql: could not connect to server: Connection refused” Error when connecting to remote database

早过忘川 提交于 2019-11-26 22:43:01
问题 I am trying to connect to a postgres database installed in a remote server using the following command: psql -h host_ip -U db_username -d db_name This the error that occurs: psql: could not connect to server: Connection refused Is the server running on host "" and accepting TCP/IP connections on port 5432? Postgres installed version is 9.4. Host operating system : Ubuntu 15.04 Client operating system : Centos 7 I already tried the following but the issue remains unresolved: Edited pg_hba.conf

PG::UndefinedTable: ERROR: missing FROM-clause entry for table when using joins and where

倾然丶 夕夏残阳落幕 提交于 2019-11-26 22:41:05
问题 I have two models, Courier and Order . I have the following query below: active_couriers = Courier. available_courier_status. where(:service_region_id => @service_region.id). includes(:orders) This query works, however, it pulls in all orders. I want to limit the orders to only orders for the day. So I added the following query where("orders.created_at >= ?", Time.zone.now.beginning_of_day) . active_couriers = Courier. available_courier_status. where(:service_region_id => @service_region.id).

Importing .csv with timestamp column (dd.mm.yyyy hh.mm.ss) using psql \copy

穿精又带淫゛_ 提交于 2019-11-26 21:36:30
问题 I'm trying to import data from a .csv file into a postgresql 9.2 database using the psql \COPY command (not the SQL COPY). The input .csv file contains a column with a timestamp in the dd.mm.yyyy hh.mm.ss format. I've set the database datestyle to DMY using. set datestyle 'ISO,DMY' Unfortunately, when I run the \COPY command: \COPY gc_test.trace(numpoint,easting,northing,altitude,numsats,pdop,timestamp_mes,duration,ttype,h_error,v_error) FROM 'C:\data.csv' WITH DELIMITER ';' CSV HEADER

Postgresql: Scripting psql execution with password

末鹿安然 提交于 2019-11-26 21:24:22
How can I call psql so that it doesn't prompt for a password ? This is what I have: psql -Umyuser < myscript.sql However, I couldn't find the argument that passes the password, and so psql always prompts for it. Reece There are several ways to authenticate to PostgreSQL. You may wish to investigate alternatives to password authentication at https://www.postgresql.org/docs/current/static/client-authentication.html . To answer your question, there are a few ways provide a password for password-based authentication. The obvious way is via the password prompt. Instead of that, you can provide the