postgresql-9.3

How to cast varchar to boolean

夙愿已清 提交于 2020-06-27 08:03:17
问题 I have a variable 'x' which is varchar in staging table, but it is set to boolean in target table which has 'true' and 'false' values. How can I convert varchar to boolean in postgresql? 回答1: If the varchar column contains one of the strings (case-insensitive): t , true , y , yes , on , 1 f , false , n , no , off , 0 you can simply cast it to boolean, e.g: select 'true'::boolean, 'false'::boolean; bool | bool ------+------ t | f (1 row) See SQLFiddle. 回答2: For Redshift, I had the best luck

Access PostgreSQL server from LAN [closed]

南笙酒味 提交于 2020-03-17 05:02:51
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I've been trying to edit pg_hba.conf file in order to be able to access the server using just the IP address with, so far, no success. For example, I can access using «localhost», but I want to access using the IP address that my router gave me wich is something like 192.168.1.X This is mi pg_hba

PostgreSQL 9.3: Display result in specific format using array_agg function

风流意气都作罢 提交于 2020-02-05 13:52:48
问题 I want to show the given records in the following table into the specific format which is shown below in the table. Creating table: Test_1 CREATE TABLE Test_1 ( ColumnA varchar, ColumnB varchar ); Insertion of records: INSERT INTO Test_1 values('A101','B101'),('A102','B102'), ('A103','B103'),('A104','B104'), ('A105','B105'),('A106','B106'), ('A107','B107'),('A108','B108'), ('A109','B109'),('A201','B201'); I want to show the result like this: Expected Result : ColumnA ColumnX -----------------

Inserting valid json with copy into postgres table

给你一囗甜甜゛ 提交于 2020-01-29 10:47:41
问题 Valid JSON can naturally have the backslash character: \. When you insert data in a SQL statement like so: sidharth=# create temp table foo(data json); CREATE TABLE sidharth=# insert into foo values( '{"foo":"bar", "bam": "{\"mary\": \"had a lamb\"}" }'); INSERT 0 1 sidharth=# select * from foo; data \----------------------------------------------------- {"foo":"bar", "bam": "{\"mary\": \"had a lamb\"}" } (1 row) Things work fine. But if I copy the JSON to a file and run the copy command I

Postgres function: return multiple tables

非 Y 不嫁゛ 提交于 2020-01-23 12:11:35
问题 Is it possible to return several result sets of different types from postgres function? Something like: CREATE OR REPLACE FUNCTION getUserById() RETURNS setof ??? AS $$ BEGIN return query select id, name /* and other columns */ from users where id = 1; return query select id, phone_number from user_phones where user_id = 1 END $$ LANGUAGE plpgsql; I don't want to use joins because several phones for user are possible. Also it would be great to avoid using cursors. It's possible in MS SQL and

Laravel 5.5 why is exception not thrown by foreign key violation from delete method?

我是研究僧i 提交于 2020-01-20 06:08:28
问题 Update 3: This problem from 9 months ago persists with Laravel 5.8 and Postgresql 11 on Windows 10 in a Laragon environment and Apache 2.4 on an Ubuntu machine. Does the Eloquent Model instance delete() method simply ignore foreign key constraints? It's baffling: I have two tables in a Postgresql 9.3 database, companies and sites. There is a one-to-many relationship between them with companies on the one side. There is a foreign key constraint that prevents the deletion of a company if sites

Laravel 5.5 why is exception not thrown by foreign key violation from delete method?

∥☆過路亽.° 提交于 2020-01-20 06:07:38
问题 Update 3: This problem from 9 months ago persists with Laravel 5.8 and Postgresql 11 on Windows 10 in a Laragon environment and Apache 2.4 on an Ubuntu machine. Does the Eloquent Model instance delete() method simply ignore foreign key constraints? It's baffling: I have two tables in a Postgresql 9.3 database, companies and sites. There is a one-to-many relationship between them with companies on the one side. There is a foreign key constraint that prevents the deletion of a company if sites

Slow Postgres 9.3 queries

拥有回忆 提交于 2020-01-15 03:49:26
问题 I'm trying to figure out if I can speed up two queries on a database storing email messages. Here's the table: \d messages; Table "public.messages" Column | Type | Modifiers ----------------+---------+------------------------------------------------------- id | bigint | not null default nextval('messages_id_seq'::regclass) created | bigint | updated | bigint | version | bigint | threadid | bigint | userid | bigint | groupid | bigint | messageid | text | date | bigint | num | bigint |

How to install sqlite or postgresql on windows 8 for a ruby on rails setup?

对着背影说爱祢 提交于 2020-01-13 16:30:31
问题 I've been trying to install a database as part of my ruby on rails setup. I'm running a 64 bit windows 8, a x64 based machine. My ruby version is 2.1.3p242, rails version is 4.0.0, sqlite3 version is 3.8.6 and postgresql version is 9.3 I first tried to install sqlite3 by following the steps given in this SO answer but I get this error `require': Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. My database.yml has

How to install sqlite or postgresql on windows 8 for a ruby on rails setup?

淺唱寂寞╮ 提交于 2020-01-13 16:30:14
问题 I've been trying to install a database as part of my ruby on rails setup. I'm running a 64 bit windows 8, a x64 based machine. My ruby version is 2.1.3p242, rails version is 4.0.0, sqlite3 version is 3.8.6 and postgresql version is 9.3 I first tried to install sqlite3 by following the steps given in this SO answer but I get this error `require': Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. My database.yml has