Posts

Showing posts with the label postgresql

Why do we need template0 and template1 on postgresql?

Why do we need template0 and template1 on postgresql? I'm a beginner on postgresql. I have faced many difficulties while installing and connecting the database with the pgadmin, I learned a lot of things from the mistakes I do. Now my doubt is why should the l shows the template0 and template1, I searched on the web but unfortunately I didn't find the rightful resources, but I can find that after the removal of both DB(template0 & template1) we cant create a Database. I don't know how you searched for it, this is literally the first and second results in google for "template0". – eurotrash Jul 1 at 10:44 1 Answer 1 As the name indicates, those are template databases for creating new databases. template1 is the one used by defau...

Error in Pentaho Data Integrator - invalid byte sequence for encoding “UTF8”: 0x00

Error in Pentaho Data Integrator - invalid byte sequence for encoding “UTF8”: 0x00 Error getting while insert bulk rows with Pentaho Data Interrogator. I am using PostgreSQL ERROR: invalid byte sequence for encoding "UTF8": 0x00 1 Answer 1 PostgreSQL is very strict content of text fields, and doesn't allow 0x00 in utf8 encoded fields. You should to fix your input data. Some possible solution https://superuser.com/questions/287997/how-to-use-sed-to-remove-null-bytes By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

I need postgresql version of this function

I need postgresql version of this function I am newbie to postgresql and I need a postgresql version of this function - could you help me please? CREATE FUNCTION [dbo].[getpersonname] (@commid INT) RETURNS VARCHAR(255) AS BEGIN DECLARE @personnname varchar(255) SELECT @personnname = COALESCE(@personname + ',', '') + ISNULL(CONVERT(VARCHAR(50), pers.personnname ),'') FROM dbo.comlink comli INNER JOIN dbo.person pers ON personid= comli_personid WHERE comli.comli_commid = @commid RETURN @personnname END What does the function do? – a_horse_with_no_name Jul 1 at 5:11 1 Answer 1 If I understand that code correctly it returns all names separated with c...

Best practice for clearing a form field when using Postgres Array column in a Rails 5.2 app?

Best practice for clearing a form field when using Postgres Array column in a Rails 5.2 app? I'm building a Rails 5.2 application that has a Postgres array column to store tags on a Post model. The migration I created looks like this... class AddTagsToPosts < ActiveRecord::Migration[5.2] def change change_table :posts do |t| t.string :tags, array: true, default: end end end Since setting the default value is required (?...I failed to find a way to get a PG array column to work without setting the default value of tags to an empty array), what is the best practice to remove the default value () from being auto filled on a Rails new/edit form without using JS? 1 Answer 1 <% 3.times do |num| %> <%= form.text_field :tags, multiple: true, class: "form-control", value: @post.tags[num] %> <% end %> By clickin...

Poor regex performance for word matching on postgres

Poor regex performance for word matching on postgres I have a list of blocked phrases and I want to match for the existence of those phrases in user inputed text, but performance is very bad. I am using this query : SELECT value FROM blocked_items WHERE lower(unaccent( 'my input text' )) ~* ('[[:<:]]' || value || '[[:>:]]') LIMIT 1; After my investigation I found out that world boundries [[:<:]] and [[:>:]] perform very badly knowing that blocked_items has 24k records in it. [[:<:]] [[:>:]] For instance when I try to run this one: SELECT value FROM blocked_items WHERE lower(unaccent( 'my input text ' )) ilike ('%' || value || '%') LIMIT 1; it's very fast compared to the first one. The problem is that I need to keep the test for word boundries. This check is performed frequently on a large program so the performance is very important for me. Do you guys have any suggestions for making this faster? EXPLIAN ANALYZE s...