首页
\
问答
\
使用未知字符串的String.matches使用“Unclosed count closure”(“Unclosed counted closure” with String.matches using unknown strings)
使用未知字符串的String.matches使用“Unclosed count closure”(“Unclosed counted closure” with String.matches using unknown strings)
下面的代码
String str1, str2; // code that assigns contents to str1 and str2 if (!str1.matches(str2)) something=false;
如果str2包含一个特殊字符,例如{,则产生一个“Unclosed count closure”异常。 如果我不知道str2或str1的内容是什么,我怎么能避免这种情况发生? 是否可以转义未知字符串中的字符?
The following code
String str1, str2; // code that assigns contents to str1 and str2 if (!str1.matches(str2)) something=false;
produces an "Unclosed counted closure" exception if str2 contains a special character such as {. How can I avoid this happening if I do not know what will be the contents of str2 or str1? Is it possible to escape characters in an unknown string?
原文:https://stackoverflow.com/questions/20752647
更新时间:2022-08-28 09:08
最满意答案
像这样尝试
CREATE OR REPLACE FUNCTION truncate_schema(_schema character varying) RETURNS void AS $BODY$ declare selectrow record; begin for selectrow in select 'TRUNCATE TABLE ' || quote_ident(_schema) || '.' ||quote_ident(t.table_name) || ' CASCADE;' as qry from ( SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema = _schema )t loop execute selectrow.qry; end loop; end; $BODY$ LANGUAGE plpgsql
try like this
CREATE OR REPLACE FUNCTION truncate_schema(_schema character varying) RETURNS void AS $BODY$ declare selectrow record; begin for selectrow in select 'TRUNCATE TABLE ' || quote_ident(_schema) || '.' ||quote_ident(t.table_name) || ' CASCADE;' as qry from ( SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema = _schema )t loop execute selectrow.qry; end loop; end; $BODY$ LANGUAGE plpgsql
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
您应该能够select * from information_schema.tables运行select * from information_schema.tables以获取Postgres为特定数据库管理的每个表的列表。 您还可以添加一个where table_schema = 'information_schema'来查看信息模式中的表。 You should be able to just run select * from information_schema.tables to get a li ...
-
如何删除Postgresql中的所有表而不是该模式?(How do I remove all tables and not the schema in Postgresql?)[2023-07-26]
尝试这个: select 'drop table if exists "' || tablename || '" cascade;' from pg_tables where schemaname = 'jason'; 从stackoverflow.com/questions/3327312/drop-all-tables-in-postgresql 并运行命令返回! Try this: select 'drop table if exists "' || tablename || '" cas ... -
Postgresql - 如何在具有相同模式的多个表上运行查询(Postgresql - how to run a query on multiple tables with same schema)[2021-09-28]
你应该看看PostgreSQL中的表继承 ,它们准确地说明了你所说的内容。 例如,您可以创建表parent_tbl: CREATE TABLE parent_tbl (id INTEGER, name VARCHAR(32), weight numeric, age INTEGER); 然后将表链接到此父表: ALTER TABLE tbl_a INHERIT parent_tbl; ALTER TABLE tbl_b INHERIT parent_tbl; ALTER TABLE tbl_c INHER ... -
对于您的架构( 注意模式名称后的周期 ): \dt my_schema. 要么: SET search_path TO my_schema, public; \dt 对于所有模式: \dt *. For your schema (note the period after the schema name): \dt my_schema. Or: SET search_path TO my_schema, public; \dt For all schemas: \dt *.
-
在所有模式中: => \dt *.* 在特定模式中: => \dt public.* 可以使用一些限制的正则表达式 \dt (public|s).(s|t) List of relations Schema | Name | Type | Owner --------+------+-------+------- public | s | table | cpn public | t | table | cpn s | t | table | cpn ...
-
在PostgreSQL中截断模式中的所有表[重复](Truncating all the tables in a schema in PostgreSQL [duplicate])[2023-08-29]
像这样尝试 CREATE OR REPLACE FUNCTION truncate_schema(_schema character varying) RETURNS void AS $BODY$ declare selectrow record; begin for selectrow in select 'TRUNCATE TABLE ' || quote_ident(_schema) || '.' ||quote_ident(t.table_name) || ' CASCADE;' as ... -
好的,我正在回答我自己的问题只是为了澄清任何其他人(没有时间阅读文档或想要更简化的版本): 您可以将Schema视为命名空间/包(就像在Java或C ++中一样)。 例如,假设mydb是我们数据库的名称, A和B是同一数据库( mdb )中存在的两个不同模式的名称。 现在,我们可以在同一个数据库中的两个不同模式中使用相同的表名: mydb -> A -> myTable mydb -> B -> myTable 希望,这澄清了你的答案。 有关更多详细信息: PostgreSQL 9.3.1文档 - 5.7 ...
-
我想你熟悉PostgreSQL 模式的概念。 你的应用程序正在寻找数据库中的django架构(可能不存在),因为你已经明确告诉了它。 'options': '-c search_path=django' 对于每个应用程序,创建一个适当命名的模式并在search_path指定它。 I suppose you are familiar with the concept of PostgreSQL schemas. Your app is looking for the django schema ...
-
您将数据插入到temporal.countries和history.countries表中,后者继承自前者。 这是错误的做法。 您只应使用其他属性插入history.countries 。 然后,当您查询temporal.countries您会看到一条记录,但没有有效的from / to信息。 更新记录后,您将获得重复记录。 使用您当前的方法无法解决这个问题。 但是你开始并不需要继承。 您可以有两个单独的表,然后创建一个视图public.countries ,它返回temporal.countries当前有 ...