postgresql-9.4

How to cast varchar to boolean

烈酒焚心 提交于 2020-06-27 08:03:45
问题 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

How to cast varchar to boolean

萝らか妹 提交于 2020-06-27 08:03:41
问题 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

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

Using \COPY to load CSV with JSON fields into Postgres

天大地大妈咪最大 提交于 2020-06-25 18:12:57
问题 I'm attempting to load TSV data from a file into a Postgres table using the \COPY command. Here's an example data row: 2017-11-22 23:00:00 "{\"id\":123,\"class\":101,\"level\":3}" Here's the psql command I'm using: \COPY bogus.test_table (timestamp, sample_json) FROM '/local/file.txt' DELIMITER E'\t' Here's the error I'm receiving: ERROR: invalid input syntax for type json DETAIL: Token "sample_json" is invalid. CONTEXT: JSON data, line 1: "{"sample_json... COPY test_table, line 1, column

Using \COPY to load CSV with JSON fields into Postgres

こ雲淡風輕ζ 提交于 2020-06-25 18:10:31
问题 I'm attempting to load TSV data from a file into a Postgres table using the \COPY command. Here's an example data row: 2017-11-22 23:00:00 "{\"id\":123,\"class\":101,\"level\":3}" Here's the psql command I'm using: \COPY bogus.test_table (timestamp, sample_json) FROM '/local/file.txt' DELIMITER E'\t' Here's the error I'm receiving: ERROR: invalid input syntax for type json DETAIL: Token "sample_json" is invalid. CONTEXT: JSON data, line 1: "{"sample_json... COPY test_table, line 1, column

Using \COPY to load CSV with JSON fields into Postgres

回眸只為那壹抹淺笑 提交于 2020-06-25 18:10:01
问题 I'm attempting to load TSV data from a file into a Postgres table using the \COPY command. Here's an example data row: 2017-11-22 23:00:00 "{\"id\":123,\"class\":101,\"level\":3}" Here's the psql command I'm using: \COPY bogus.test_table (timestamp, sample_json) FROM '/local/file.txt' DELIMITER E'\t' Here's the error I'm receiving: ERROR: invalid input syntax for type json DETAIL: Token "sample_json" is invalid. CONTEXT: JSON data, line 1: "{"sample_json... COPY test_table, line 1, column

delete emp table data using ssis package

梦想与她 提交于 2020-06-17 12:56:19
问题 I want delete the data in the target server(postgres) tables data using ssis package. database : postgres server Table : emp in execute sql task :scriptis: delete from emp and connection used odbc when i run the executesql task in ssis package if emp table have data then its working fine and i am getting the error when emp table donot have data. [Execute SQL Task] Error: Executing the query "delete from emp usin..." failed with the following error: "Error HRESULT E_FAIL has been returned from

delete emp table data using ssis package

送分小仙女□ 提交于 2020-06-17 12:56:03
问题 I want delete the data in the target server(postgres) tables data using ssis package. database : postgres server Table : emp in execute sql task :scriptis: delete from emp and connection used odbc when i run the executesql task in ssis package if emp table have data then its working fine and i am getting the error when emp table donot have data. [Execute SQL Task] Error: Executing the query "delete from emp usin..." failed with the following error: "Error HRESULT E_FAIL has been returned from

Postgres Match All array values to same column with and condition ---updated

核能气质少年 提交于 2020-05-13 11:46:58
问题 I have table table_a with following columns id event_id 1 101 1 102 1 103 2 105 2 103 2 106 I and to search (101, 103) with and conditions similar to IN query with OR condition For example id 1 match both for 101 and 103 event_id; For this I write following query but it not working. select * from table_a where event_id = ALL(ARRAY[101,103]); UPDATED--------------------------- And I have another problem let say id is foreign of another table event_categories having relation like this. id

Postgres Match All array values to same column with and condition ---updated

落爺英雄遲暮 提交于 2020-05-13 11:45:08
问题 I have table table_a with following columns id event_id 1 101 1 102 1 103 2 105 2 103 2 106 I and to search (101, 103) with and conditions similar to IN query with OR condition For example id 1 match both for 101 and 103 event_id; For this I write following query but it not working. select * from table_a where event_id = ALL(ARRAY[101,103]); UPDATED--------------------------- And I have another problem let say id is foreign of another table event_categories having relation like this. id