postgresql-9.2

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

Postgres LIKE with column value as substring

*爱你&永不变心* 提交于 2020-06-13 17:58:06
问题 I'm trying to compose a WHERE statement that will match rows where a column value is a substring of another string. For example, I might have an event record with a name field of Edward Sharpe . I'd like to do something like: SELECT * FROM events WHERE(name LIKE 'Edward Sharpe and the Magnetic Zeroes'); This doesn't work. I've also various permutations of: SELECT * FROM events WHERE('%' || name || '%' LIKE 'Edward Sharpe and the Magnetic Zeroes'); Which also doesn't work. 回答1: Your second

what is the maximum length of varchar(n) in postgresql 9.2 and which is best to use varchar(n) or text?

我只是一个虾纸丫 提交于 2020-05-09 20:01:34
问题 Hi I am using postgresql 9.2 and I want to use varchar(n) to store some long string but I don't know the maximum length of character which varchar(n) supports. and which one is better to use so could you please suggest me? thanks 回答1: tl;dr: 1 GB (each character (really: codepoint) may be represented by 1 or more bytes, depending on where they are on a unicode plane - assuming a UTF-8 encoded database). You should always use text datatype for arbitrary-length character data in Postgresql now.

what is the maximum length of varchar(n) in postgresql 9.2 and which is best to use varchar(n) or text?

♀尐吖头ヾ 提交于 2020-05-09 20:01:05
问题 Hi I am using postgresql 9.2 and I want to use varchar(n) to store some long string but I don't know the maximum length of character which varchar(n) supports. and which one is better to use so could you please suggest me? thanks 回答1: tl;dr: 1 GB (each character (really: codepoint) may be represented by 1 or more bytes, depending on where they are on a unicode plane - assuming a UTF-8 encoded database). You should always use text datatype for arbitrary-length character data in Postgresql now.

How to set application name in a Postgresql JDBC url?

人盡茶涼 提交于 2020-01-28 05:01:06
问题 I want to set the application name of the connections of my application. So when I list the rows in pg_stat_activity I can have a non empty application_name column. I have setup the following JDBC url for connecting to my Postgresql database: jdbc:postgresql://localhost:5435/MyDB?application-name=MyApp I have tried also this url with no more success. jdbc:postgresql://localhost:5435/MyDB?application_name=MyApp What is the correct parameter name ? Here is my JDBC driver version: 9.1-901.jdbc4