postgresql-9.1

Group by end of period instead of start date

坚强是说给别人听的谎言 提交于 2019-12-04 18:43:51
I'm looking to aggregate data by the end date of a dataset with some leading period rather than the start. For example, I want to query a table and return the count of matching results 30 days PRIOR to the end date of the date shown in the results. The original table would contain ONLY the date a sale was made (timestamp). Example: sales_timestamp ------------------ 2015-08-05 12:00:00 2015-08-06 13:00:00 2015-08-25 12:31:00 2015-08-26 01:02:00 2015-08-27 02:03:00 2015-08-29 04:23:00 2015-09-01 12:00:00 2015-09-02 12:00:00 2015-09-08 00:00:00 An example of the resulting query output would be:

Saving timestamps in Postgres based on Java dates

青春壹個敷衍的年華 提交于 2019-12-04 18:43:48
问题 I have a Postgres database with a table that contains a timestamp ( timeOfProcessing TIMESTAMP ). I have a Java datetime value ( java.util.Date dateTime ) and want to store its value in that timestamp field (without time zone). When I do it using the query "INSERT INTO mytable(..., timeOfCreation, ...) VALUES(..., to_timestamp(" + Long.toString(dateTime.getTime()) + "),...)" and then read the saved value ( SELECT timeOfCreation FROM mytable ), they are different ( resultSet.getTimestamp(...)

PostgreSQL crosstab/pivot problems

梦想与她 提交于 2019-12-04 17:20:26
I have a prefs table, and here are the relevant columns: mydb=> SELECT pref_id, pref_name, pref_value FROM prefs; pref_id | pref_name | pref_value ---------+--------------+---------------- 1 | PagerNumber | 2125551234 2 | PagerCarrier | @att.com 3 | PagerCarrier | @something.com I want to produce something like this: section | pager_number | pager_carrier ---------+----------------+--------------- 1 | 2125551234 | 2 | | @att.com 3 | | @something.com So I used crosstab, following this example on stackoverflow: PostgreSQL Crosstab Query SELECT row_name AS section, category_1::text AS pager

Retrieving file from bytea in PostgreSQL using java

限于喜欢 提交于 2019-12-04 14:14:48
Hi I'm using the below code to retrieve the file from the postgresql bytea using java, but inside the file I'm getting numbers like 314530413142313141 File file = new File("c:/test.doc"); FileOutputStream fos = new FileOutputStream(file); ResultSet rs = st.executeQuery("SELECT * FROM test_bytea where id=" + 1); if (rs != null) { while (rs.next()) { byte[] fileBytes = new byte[1024]; InputStream is = rs.getBinaryStream("type_file"); while (is.read(fileBytes) > 0) { fos.write(fileBytes); } // use the stream in some way here } rs.close(); } Please let me know what goes wrong in my code? The data

Postgres SELECT* FROM table WHERE column-varchar==“string-example”?

半世苍凉 提交于 2019-12-04 12:57:01
I have the following table: CREATE TABLE lawyer ( id SERIAL PRIMARY KEY, name VARCHAR NOT NULL UNIQUE, name_url VARCHAR check(translate(name_url, 'abcdefghijklmnopqrstuvwxyz-', '') = '') NOT NULL UNIQUE ); I want to SELECT * FROM lawyer where name_url = "john-doe" Character literals are put into single quotes: SELECT * FROM lawyer where name_url = 'john-doe'; See the manual for details: https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS Looking for exact match: select column1, column2 from mytable where column2 like 'string'; Pattern Match can be

Running PostgreSQL with Supervisord

一曲冷凌霜 提交于 2019-12-04 12:49:14
问题 I want to run PostgreSQL 9.1 using Supervisor on Ubuntu 10.04. At the moment, I manually start PostgreSQL using the init script: /etc/init.d/postgresql start According to this post: http://nicksergeant.com/using-postgresql-with-supervisor-on-ubuntu-1010/, I need to modify the PostgreSQL config to make it run on TCP port instead of Unix socket, in order to make PostgreSQL work with Supervisor. I have two questions regarding this approach: Considering this is more of hack, is there any

PostgresQL Automating VACUUM FULL for bloated tables

牧云@^-^@ 提交于 2019-12-04 11:34:01
问题 We have a product using PostgreSQL database server that is deployed at a couple of hundred clients. Some of them have gathered tens of gigabytes of data over the years. So in the next version we will introduce automated cleanup procedures which will gradually archive and DELETE old records during nightly batch jobs. If I understand correctly, autovacuum will kick in and analyze and reorganize the tuples, so the performance will be like it was when fewer records existed. The actual disk space

JPA with Hibernate 3.6.8.Final, PostgreSQL 9.1, SQLGrammarException - configuration issue? Weird SQL statement

我是研究僧i 提交于 2019-12-04 08:37:58
Edit : SOLVED Right. I found the thing that confused me. I use pgadmin to create tables and others database internals, checked right now: if at least one letter in the name (table name, column name, pk name, etc) is in the upper case, then pgadmin uses it in the SQL creation script as it is, using double quotes, so PostgreSQL interprets the name as it was written. If run the following script: CREATE TABLE SAMPLE ( ID integer NOT NULL, TITLE character varying(100) NOT NULL, CONSTRAINT SAMPLE_ID_PK PRIMARY KEY (ID) ) WITH ( OIDS=FALSE ); ALTER TABLE SAMPLE OWNER TO postgres;_ it creates

How to Disconnect from a database and go back to the default database in PostgreSQL?

只愿长相守 提交于 2019-12-04 07:56:07
问题 I'm using PostgreSql version : postgres=# select version(); version ------------------------------------------------------------- PostgreSQL 9.2.4, compiled by Visual C++ build 1600, 64-bit (1 row) i had connected to a database from postgres=# to newdb=# .... Now i'm in newdb=# Database i want to disconnect it and go back to postgres=# database .... How to do this ? I have tried with disconnect newdb; but its giving erroe as:: postgres=# create database newdb; CREATE DATABASE postgres=# \c

postgreSQL 9.1.18 version installation

故事扮演 提交于 2019-12-04 05:58:28
问题 I downloaded PostgreSQL 9.1.18 version and I have windows 32 bit. I'm trying to install this database first time in my computer so, when I start installing PostgreSQL 9.1.18 at the last step it shows me error. Before the installation I created a folder in c drive with the name PostgreSQL then went to security tab and added account PostgreSQL and give full control. When I install PostgreSQL 9.1.18 I select this folder but again at the end same error occurred. ERROR "Problem running post