postgresql-9.2

Ruby: Outputting Sequel model associations

∥☆過路亽.° 提交于 2019-12-23 05:23:58
问题 I don't think this is possible using just Sequel models, but what I would like to do is have my parent model ( Author ) output its child model ( Book ) when I do something like Author.to_json . Here is my code: require 'sequel' require 'json' db = Sequel.connect('postgres://localhost/testing'); class Sequel::Model self.plugin :json_serializer end class Author < Sequel::Model(:author) one_to_many :book, key: :author_id, primary_key: :id def get_author Author.each do |e| books = Array.new e

how to call postgres function with hibernate criteria

亡梦爱人 提交于 2019-12-23 04:02:27
问题 I am getting sorted results using hibernate criteria which generates the below sql: select * from mytable order by name asc; This is how i do it with hiberante criteria: criteria.addOrder(Order.asc("name")); Now, i have created a function in postgres DB as: customSort(text) and want to use with hibernate criteria such that following sql is generated: select * from mytable order by customSort(name) asc; How can i call this function in hibernate to make my custom sorting and generate equivalent

Handling EXCEPTION and return result from function

瘦欲@ 提交于 2019-12-22 09:50:04
问题 This is my code CREATE OR REPLACE FUNCTION test_excep (arg INTEGER) RETURNS INTEGER AS $$ DECLARE res INTEGER; BEGIN res := 100 / arg; BEGIN EXCEPTION WHEN division_by_zero THEN RETURN 999; END; RETURN res; END; $$ LANGUAGE plpgsql; That is, I need returned "999", if happened division by zero, but this: SELECT test_excep(0) returns error: division by zero CONTEXT: PL/pgSQL function test_excep(integer) line 4 at assignment What is wrong in my code? 回答1: The EXCEPTION clause needs to be in the

Conditional Order By

岁酱吖の 提交于 2019-12-21 20:47:11
问题 I have a table where there is a set of routes with a start label and end label. each row has a column "progres" which is the column where to apply the global "order by" clause, and finally a selection column that tells which label types must be ordered (Odd, Even or All). if LabelStart > LabelEnd => order by ASC else by DESC for example here are the routes path Routes ID RouteID, Progres, LabelStart, LabelEnd Type 1 1 5 1 21 O 2 1 10 10 2 E 4 2 15 2 25 A 5 3 20 1 11 O 6 3 22 4 10 E 7 4 30 5

How to find first free time in reservations table in PostgreSql

≯℡__Kan透↙ 提交于 2019-12-21 20:15:20
问题 Reservation table contains reservations start dates, start hours and durations. Start hour is by half hour increments in working hours 8:00 .. 18:00 in work days. Duration is also by half hour increments in day. CREATE TABLE reservation ( startdate date not null, -- start date starthour numeric(4,1) not null , -- start hour 8 8.5 9 9.5 .. 16.5 17 17.5 duration Numeric(3,1) not null, -- duration by hours 0.5 1 1.5 .. 9 9.5 10 primary key (startdate, starthour) ); table structure can changed if

tsvector only supports English?

雨燕双飞 提交于 2019-12-21 20:07:01
问题 I did the following: ALTER TABLE blog_entry ADD COLUMN body_tsv tsvector; CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON blog_entry FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(body_tsv, 'pg_catalog.english', body); CREATE INDEX blog_entry_tsv ON blog_entry USING gin(body_tsv); UPDATE blog_entry SET body_tsv=to_tsvector(body); Now this is working: SELECT title FROM blog_entry WHERE body_tsv @@ plainto_tsquery('hello world'); But when trying to search for non-English text,

PostgreSQL “initdb” (Database Initialization) on Linux

若如初见. 提交于 2019-12-21 14:35:08
问题 I'm working on creating a Database Cluster (single database) in PostgreSQL 9.x working on a Linux system (CentOS - RedHat - Fedora). I've installed the correct PostgreSQL packages (server & client) however, I'm unable to create a database and get some type of initializing dependencies error: Bus Error / Exit Code 135 . I've changed my user to "postgres" with "su postgres" and then tried to initialize the database with "initdb" (this may be the problem) Installed: postgresql-libs-9.2.13-1.el7

Where can I get pldbgapi.sql in order to install the debugger for postgresql?

浪尽此生 提交于 2019-12-21 04:01:44
问题 I am trying to install the debugger for postgresql on Linux so I can use pgAdmin to debug my functions. I've set up my postgresql.conf file. However, I can't find pldbgapi.sql . Postgresql is installed at /usr/pgsql-9.2/ . The directory /usr/pgsql-9.2/share/ exists, but /usr/pgsql-9.2/share/contrib does not exist. Where can I find the file or download it? Thanks! 回答1: I've found out it works if I run the contents of this file share\extension\pldbgapi--1.0.sql There is also this readme for the

how to change PostgreSQL data directory?

筅森魡賤 提交于 2019-12-21 02:51:13
问题 I am having a problem changing the data directory on postgresql 9.2 on windows7: i`m trying to change my data directory: how can i change data directory on postgreSQL with pgAdmin? 回答1: This not possible from within pgAdmin (or any other SQL client because you need to stop the Postgres server in order to move the data directory) To move the directory, use these steps: Stop Postgres (you can use the control panel to find the correct service name) net stop <name_of_the_service> Make sure

PostgreSQL 9.2 - Convert TEXT json string to type json/hstore

徘徊边缘 提交于 2019-12-20 11:49:41
问题 I have a TEXT column containing valid JSON string. CREATE TABLE users(settings TEXT); INSERT INTO users VALUES ('{"language":"en","gender":"male"}'); INSERT INTO users VALUES ('{"language":"fr","gender":"female"}'); INSERT INTO users VALUES ('{"language":"es","gender":"female"}'); INSERT INTO users VALUES ('{"language":"en","gender":"male"}'); I want to transform some fields into a query-able format. A REGEXP_REPLACE for each field would do ( language field and gender field). But since it's