postgresql-9.1

Get result from query in DO satement

谁说我不能喝 提交于 2019-12-08 03:24:30
How to run SQL statement within an IF condition in plpgsql? I don't want to create or replace a function. This is what I tried: DO LANGUAGE plpgsql $$ BEGIN IF 'Khosla' = 'Khosla' THEN SELECT * FROM test_log limit 10; ELSE RAISE NOTICE 'not worked'; END IF; END; $$; ERROR: query has no destination for result data HINT: If you want to discard the results of a SELECT, use PERFORM instead. CONTEXT: PL/pgSQL function "inline_code_block" line 3 at SQL statement I also tried this but was unable to get data: DO LANGUAGE plpgsql $$ BEGIN if 'a' = 'a' THEN PERFORM * FROM test_log limit 10; else raise

PostgreSQL connection timeout

不羁岁月 提交于 2019-12-07 20:44:51
问题 I am using a desktop application with PostgreSQL database server. When I am not using application for 10 to 20 minutes continuously, the database connection is dropped . And I am using PostgresqlJDBC for database connection. Please help me on this to database connection time out. Thanks. 回答1: Sounds like you are connected via a stateful connection tracking router/firewall that has a short connection tracking timeout. Sounds like you need to enable keepalives. Take a look at the tcp_keepalives

CakePHP use wrong sequence name (PostgreSQL)

一笑奈何 提交于 2019-12-07 18:28:20
问题 When I try save some information in Postgres table, CakePHP return this error for me: array( (int) 0 => '[PDOException] SQLSTATE[42P01]: Undefined table: 7 ERRO: relação "public.cashier_transaction_transaction_num_seq" não existe Request URL: /www/cashiers/open Stack Trace: But CakePHP is correctly: this sequence doesn't exist. The correct sequence is transaction_num_seq . How can I change that IN CAKE (I can't change the database). 回答1: There seems to be an undocumented, optional

PostgreSQL Composite Primary Key and Serial increment?

♀尐吖头ヾ 提交于 2019-12-07 15:29:14
问题 I'm trying to create a table as follows: CREATE TABLE SCHEDULE ( SESSIONID SERIAL, MODULECODE VARCHAR(10), CONSTRAINT SCHEDULE_FOREIGN_KEY FOREIGN KEY (MODULECODE) REFERENCES MODULES (MODULECODE), CONSTRAINT SCHEDULE_PRIMARY_KEY PRIMARY KEY (SESSIONID, MODULECODE)); The idea being that SESSION ID would auto increment with each new row but only local to MODULECODE , for example: ---------------------- |SESSIONID|MODULECODE| |---------|----------| | 1 | A | | 2 | A | | 3 | A | | 1 | B | | 2 | B

Postgres recursive query to update values of a field while traversing parent_id

人盡茶涼 提交于 2019-12-07 14:56:10
问题 This is the table user_id | parent_id | lft --------|-----------|----- 1 | | 0 2 | 1 | 0 3 | 1 | 0 4 | 2 | 0 Here is a query to do a CTE from node 1 and traverse all the children of user_id 1 until a leaf is reached and update the value of the travesed chidren lft field to 1 WITH RECURSIVE d AS ( SELECT user_id FROM btrees WHERE user_id = 1 UNION ALL SELECT c.user_id FROM d JOIN btrees c ON c.parent_id = d.user_id ) UPDATE btrees b set lft = 1 FROM d WHERE d.user_id = b.user_id I am just

How to create multiple sequences in one table?

风格不统一 提交于 2019-12-07 08:57:02
问题 I have a table "receipts". I have columns customer_id (who had the receipt) and receipt_number. The receipt_number should start on 1 for each customer and be a sequence. This means that customer_id and receipt_number will be unique. How can I elegantly do this. Can I use the built-in sequeance functionality with CREATE SEQUENCE or similar? It seems like I would have to create a sequence for each customer, which of course is not an elegant solution. EDIT: There must be a thread-safe and idiot

Postgresql server remote connection

孤街浪徒 提交于 2019-12-07 08:32:22
问题 I am trying to set up a postgresql 9.1 server on ubuntu, for remote access of data. I have postgres properly installed, the server process is running and I am trying to configure it so that I can access the server remotely over the internet from a few other computers outside my LAN. I have already modified my pg_hba.conf with: host all all 0.0.0.0 trust and the postgresql.conf with: listen_addresses = '*' port = 5432 I have additionally modified my iptables to accept connections on port 5432.

Create PostgreSQL trigger using JDBC

妖精的绣舞 提交于 2019-12-07 06:50:21
问题 I am trying to create a PostgreSQL trigger in a Play2.0 database evolution script. The sql code is relatively easy and runs fine in pgAdminIII: CREATE OR REPLACE FUNCTION update_modified() RETURNS TRIGGER AS $$ BEGIN NEW.modified = now(); RETURN NEW; END; $$ LANGUAGE 'plpgsql'; However, I get an error when running the evolution: ERROR: unterminated dollar-quoted string at or near "$$ BEGIN NEW.modified = now()" . The SQL code seems to get truncated at the first semicolon encountered in the

Why does pg_restore return “options -d/--dbname and -f/--file cannot be used together”?

邮差的信 提交于 2019-12-07 06:19:43
问题 The following Windows batch script fails on the line with database restore: @Echo off set Path=C:\Program Files (x86) set Backup_Path=C:\Program Files (x86) c: cd \ cd C:\Program Files (x86)\PostgreSQL\9.1\bin @echo "Wait ..." setlocal set PGPASSWORD=1234 psql.exe -U postgres -c "create database Mydata" "C:\Program Files (x86)\PostgreSQL\9.1\bin\pg_restore.exe" -h localhost -U postgres -d Mydata -f "Mydata.backup" pause endlocal The error is: pg_restore : -d / - dbname and -f / - file can not

PostgreSQL: Loop Until a Condition is True

与世无争的帅哥 提交于 2019-12-07 05:15:18
问题 I am trying to write a query which "loops" through a database starting at a specified value until a condition is true. For example, suppose I have the following entries in TABLE example: id, parent, cond 1, , True 2, 1 , False 3, 1 , False 4, 2 , False ... ... ... I want a query which takes as input (for instance) 4, and will return the values of 2 and 1. The process being that the query matches the id, and if cond==False, will look at the parent (id = 2). Since cond = False in the second row