postgresql-9.1

How reimplement BCryptPasswordHasher of django with postgres 9.1

断了今生、忘了曾经 提交于 2020-01-06 20:53:23
问题 I have a postgres 9.1 database that is used by both a django website and a application server. Currently, I use the old SHA1 authentication in both system, but will upgrade to bcrypt. I have this: CREATE OR REPLACE FUNCTION random_string(length INTEGER, OUT RETURNS TEXT) AS $$ BEGIN IF length < 0 THEN raise exception 'Given length cannot be less than 0'; END IF; RETURNS = libs.gen_salt('bf', length); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION encryp_TEXT(_TEXT TEXT, OUT RETURNS TEXT

split single row into multiple rows in SQL

本小妞迷上赌 提交于 2020-01-06 03:57:05
问题 In my table there are two fields start and stop which stores the start time and stop time respectively. for example the Start time = 2014-01-01 23:43:00 and stop = 2014-01-03 03:33:00. This timestamp needs to brokendown to. 1=> 2014-01-01 23:43:00 - 2014-01-02 00:00:00, as date 2014-01-01 2=> 2014-01-02 00:00:01 - 2014-01-03 00:00:00, as date 2014-01-02 3=> 2014-01-03 00:00:01 - 2014-01-03 03:33:00, as date 2014-01-03 as three different rows. Here the problem is the difference in stop and

Finding if current row is last row to be selected from database

两盒软妹~` 提交于 2020-01-05 12:46:46
问题 I am selecting list of periods from database. If current row is first row then the period starts with date and I can find the interval between period start like this: SELECT ... CASE WHEN row_number() OVER(ORDER BY r.created_at ASC) = 1 THEN r.created_at - r.created_at::date ELSE NULL END AS period ... FROM mytable r How can I do the same to last row? To find the time between the r.created_at of last row and midnight of its date. I am aware of first and last functions in PostgreSQL (https:/

PostGIS Error: Could not choose a best candidate function

£可爱£侵袭症+ 提交于 2020-01-05 07:38:09
问题 When creating a View, I get the error function populate_geometry_columns(unknown) is not unique . A book that I'm reading used this, but its giving me an error. What could have gone wrong for me? Query: CREATE OR REPLACE VIEW ch03.vw_paris_points AS SELECT gid, osm_id, ar_num, geom, tags->'name' As place_name, tags->'tourism' As tourist_attraction FROM ch03.paris_hetero WHERE ST_GeometryType(geom) = 'ST_Point'; SELECT populate_geometry_columns('ch03.vw_paris_points'); Error: ERROR: function

Split values from an interval and group by isoweek - Postgresql

≯℡__Kan透↙ 提交于 2020-01-04 09:18:05
问题 I want to "distribute" or "split" hours from a single task into iso weeks based on a date interval. But I do not have a clue how to do this in Postgresql. CREATE TABLE task (id int4, start date, stop date, hr int4); INSERT INTO task (id, start, stop, hr) VALUES (1, '2017-01-01','2017-01-31', 80), (2, '2017-01-01','2017-02-28', 120); The desired output of these 2 tasks should be like: The 80 hr of task 1 should be distributed into 5 weeks 201701 16 hr 201702 16 hr 201703 16 hr 201704 16 hr

How to access EntityManager inside Entity class in EJB3

牧云@^-^@ 提交于 2020-01-04 05:27:17
问题 I need to execute a db query inorder to set the extra column "The order by column" in a many to many association table. so I need to access the db sequence from inside the Entity class and and select the nextval of the sequence and assign it to the order_by column in @prepersist lifecycle callback method. @Entity public class ProductWishlist implements Serializable { .... @Column(name="ORDER_BIT") private long orderBit; // getter setter // ....... @Prepersist public void setOrderBit

PostgreSQL forces lowercase names?

…衆ロ難τιáo~ 提交于 2020-01-03 07:20:12
问题 Just started to learn PostgreSQL 9.1 on linux through C and libpq. For now I check connection, connect, create database, create table and other basic stuff. But I noted that during table creating PQ converts my database name to lowercase. Then I see that table names and field names are also forced to lowercase. Howewer, when I try to connect with uppercase (original) name of database I get warning that asked database don't exist. Best of all will be that all names stays as written. Is this

Insert trigger ends up inserting duplicate rows in partitioned table

怎甘沉沦 提交于 2020-01-03 02:31:27
问题 I have a partitioned table with (what I think) the appropriate INSERT trigger and a few constraints on it. Somehow, INSERT statements insert 2 rows for each INSERT : one for the parent and one for the appropriate partition. The setup briefly is the following: CREATE TABLE foo ( id SERIAL NOT NULL, d_id INTEGER NOT NULL, label VARCHAR(4) NOT NULL); CREATE TABLE foo_0 (CHECK (d_id % 2 = 0)) INHERITS (foo); CREATE TABLE foo_1 (CHECK (d_id % 2 = 1)) INHERITS (foo); ALTER TABLE ONLY foo ADD

Postgresql: Ordering columns to match custom criteria

南笙酒味 提交于 2020-01-02 10:15:56
问题 I'm having trouble sorting the result of a query. After executing this query: SELECT id_doc_header, id_clasificacion_doc FROM cabecera_documento INNER JOIN tipo_doc USING (id_tipo_doc) INNER JOIN clasificacion_documento USING (id_clasificacion_doc) WHERE finalizado = 'f' AND cod_exp = '10-APC-2013' AND id_clasificacion_doc in(2,3,4,5) ORDER BY case when Id_clasificacion_doc = 5 THEN 5 when Id_clasificacion_doc = 3 THEN 3 when Id_clasificacion_doc = 2 THEN 2 when Id_clasificacion_doc = 4 THEN

Postgres database crash when installing plpython

不问归期 提交于 2020-01-02 05:46:46
问题 I'm trying to install plpython in my Postgres 9.1 but it crashes the server: postgres@dataserver1:~> /opt/postgres/9.1/bin/psql -d mydb psql.bin (9.1.4) Type "help" for help. mydb=# create language 'plpythonu'; The connection to the server was lost. Attempting reset: Failed. I have python 2.6.8 installed and the handler is correcty declared in the system: select tmplname, tmplhandler, tmpllibrary from pg_pltemplate where tmplname like 'plpython%' "plpythonu" | "plpython_call_handler" | "