psql

How to set timezone for Postgres psql?

℡╲_俬逩灬. 提交于 2019-11-28 07:21:26
How do I set timezone for psql to something other than my default (US/Central)? Here's what I've tried so far: $ psql psql (9.1.4, server 9.0.4) ... $ psql -c 'show timezone' TimeZone ------------ US/Central $ psql --set=timezone=US/Eastern -c 'show timezone' TimeZone ------------ US/Central $ psql --variable=timezone=US/Eastern -c 'show timezone' TimeZone ------------ US/Central Edit : I don't want to change the server timezone, just the client. Edit #2 : I want it in non-interactive mode. The psql doc says: -v assignment --set=assignment --variable=assignment Perform a variable assignment,

PL/pgSQL functions: How to return a normal table with multiple columns using an execute statement

ぐ巨炮叔叔 提交于 2019-11-28 04:59:13
I've got this PL/pgSQL function which must return some users information. CREATE OR REPLACE FUNCTION my_function( user_id integer ) RETURNS TABLE( id integer, firstname character varying, lastname character varying ) AS $$ DECLARE ids character varying; BEGIN ids := ''; --Some code which build the ids string, not interesting for this issue RETURN QUERY EXECUTE 'SELECT users.id, users.firstname, users.lastname FROM public.users WHERE ids IN (' || ids || ')'; END; $$ LANGUAGE plpgsql; The problem I'm facing is that the result of the function is a single columns table like this: ╔═══╦════════════

Find the host name and port using PSQL commands

吃可爱长大的小学妹 提交于 2019-11-28 03:05:12
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? Brad Koch 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 same host. a_horse_with_no_name SELECT * FROM pg_settings WHERE name = 'port'; This command will

Alternate output format for psql

六眼飞鱼酱① 提交于 2019-11-28 02:32:29
I am using PostgreSQL 8.4 on Ubuntu. I have a table with columns c1 through cN . The columns are wide enough that selecting all columns causes a row of query results to wrap multiple times. Consequently, the output is hard to read. When the query results constitute just a few rows, it would be convenient if I could view the query results such that each column of each row is on a separate line, e.g. c1: <value of row 1's c1> c2: <value of row 1's c1> ... cN: <value of row 1's cN> ---- some kind of delimiter ---- c1: <value of row 2's c1> etc. I am running these queries on a server where I would

How to ignore errors with psql \copy meta-command

a 夏天 提交于 2019-11-28 00:32:29
问题 I am using psql with a PostgreSQL database and the following copy command: \COPY isa (np1, np2, sentence) FROM 'c:\Downloads\isa.txt' WITH DELIMITER '|' I get: ERROR: extra data after last expected column How can I skip the lines with errors? 回答1: You cannot skip the errors without skipping the whole command up to and including Postgres 9.5. There is currently no more sophisticated error handling. \copy is just a wrapper around SQL COPY that channels results through psql. The manual for COPY

Shell script to execute pgsql commands in files

☆樱花仙子☆ 提交于 2019-11-27 21:32:36
问题 I am trying to automate a set of procedures that create TEMPLATE databases. I have a set of files (file1, file2, ... fileN), each of which contains a set of pgsql commands required for creating a TEMPLATE database. The contents of the file (createdbtemplate1.sql) looks roughly like this: CREATE DATABASE mytemplate1 WITH ENCODING 'UTF8'; \c mytemplate1 CREATE TABLE first_table ( --- fields here .. ); -- Add C language extension + functions \i db_funcs.sql I want to be able to write a shell

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

心已入冬 提交于 2019-11-27 18:28:54
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). includes(:current_orders). includes(:orders). where("orders.created_at >= ?", Time.zone.now.beginning

Why psql can't connect to server?

ぐ巨炮叔叔 提交于 2019-11-27 11:06:49
问题 I typed psql and I get this: psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? I used sudo netstat -nlp | grep 5432 to see the status but nothing showed. And I searched online, somebody told me to modify pg_hba.conf but I can't locate this file. And I also tried this command sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432 . It can't work. 回答1: The error

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

邮差的信 提交于 2019-11-27 10:32:34
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? I was getting the exact same error, but the above answers didn't work for me. I had to reinstall postgresql. brew reinstall postgresql The key problem is that your postgresql was trying to find the libreadline.6.2.dylib but your readline is version 7.0 , so only 7's lib is linked.

How to Add, Delete new Columns in Sequelize CLI

 ̄綄美尐妖づ 提交于 2019-11-27 10:31:43
问题 I've just started using Sequelize and Sequelize CLI Since it's a development time, there are a frequent addition and deletion of columns. What the best the method to add a new column to an existing model? For example, I want to a new column ' completed ' to Todo model. I'll add this column to models/todo.js. Whats the next step? I tried sequelize db:migrate not working: "No migrations were executed, database schema was already up to date." 回答1: If you are using sequelize-cli you need to