小编Joh*_*zer的帖子

在 PostgreSQL 中,`print` 的 plpython(3)u 输出到哪里去了?

当我在 PostgreSQL 中创建以下函数时:

create function log( value variadic text[] )
  returns void
  language plpython3u
  as $$
    print( ' '.join( value ) + '\n' )
    $$;

do $$ begin perform log( ( 42 + 108 )::text ); end; $$;
Run Code Online (Sandbox Code Playgroud)

输出未出现在终端中(使用psql -f ...)。它会去哪里?

此外,是否有任何简单的方法(可能是扩展)可以为我提供易于使用的输出stdout/ stderr?我不想使用,select因为所有输出都带有表装饰,您可以关闭它,但只能使用psql在函数中不起作用的技巧。同样,我不想使用\echo,因为这在函数定义中不起作用。

编辑我知道plpy.notice(),但该功能也将其输出包围在一大堆混乱中。


顺便说一句,我现在的解决方案是写入文件:

create function log( value variadic text[] )
  returns void
  language plpython3u
  as $$
    with open( '/tmp/psql-output', 'a' ) as o:
      o.write( …
Run Code Online (Sandbox Code Playgroud)

python postgresql plpython

7
推荐指数
1
解决办法
1248
查看次数

如何在fontconfig中设置每个Unicode范围/代码点的字体?

我最近想出了如何fontconfig在Linux 上使用serif,sans-serif和monospaced字体设置系统默认字体; 基本上,您~/.config/fontconfig/fonts.conf使用以下内容保存XML配置文件:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

<match>
  <test qual="any" name="family"><string>serif</string></test>
  <edit name="family" binding="strong" mode="prepend_first">
    <string>Gentium</string>
    <string>Sun-ExtA</string>
    <string>HanaMinA</string>
    <string>HanaMinB</string>
    </edit>
  </match>

</fontconfig>
Run Code Online (Sandbox Code Playgroud)

这些binding="strong" mode="prepend_first"属性确保匹配规则优先于其他设置,并且字体名称序列确保字体不包含给定的代码点/字符,尝试列表中的下一个字体(此列表适用于top-to -bottom;恕我直言,它应该是一个后来更强大的逻辑,但无论如何).

这种配置的优点在于它可以在文本编辑器和终端仿真器中使用.

然而,还有一个问题:在许多情况下,给定的字体确实包含给定的字形,但另一种字体对于该代码点是可取的; 例如,它Sun-ExtA是CJK字符的一个很好的默认字体,但它也涵盖了很多很多非CJK字符,并且有一些有问题的字形.

假设我不喜欢? U+3007 IDEOGRAPHIC NUMBER ZEROin 的外观Sun-ExtA而宁愿使用HanaMinA它,我怎么能这样做fontconfig呢?很显然,我不能只优先考虑的进入HanaMinASun-ExtA,因为这将影响到所有包含在两种字体字形的.

我的预感是应该有一个涉及元素的解决方案<charset>(根据 fontconfig用户文档,"此元素至少包含一个Unicode代码点或更多的元素")和/或<range>("此元素包含范围的两个元素表示"-presumably表示一系列Unicode代码点".但是,我找不到一个如何使用这些元素的例子.

是否可以将fontconfig配置为对单个Unicode代码点或一系列代码点使用特定字体?

linux unicode fonts fontconfig

6
推荐指数
2
解决办法
928
查看次数

How to write an upsert trigger in PostgreSQL?

In PostgreSQL 9.6 and later, what is the correct way to define a trigger function that will perform an update whenever an insert would fail because of a uniqueness constraint?

I know it is straightforward to write insert ... on conflict ... do update set ... statements, but my idea is that I want to have some tables that treat repeated inserts as updates; otherwise that piece of logic would have to be taken care of by the application, not …

sql postgresql upsert

3
推荐指数
1
解决办法
1434
查看次数

如何打印代码,PostgreSQL / plpgsql 异常的类型

给定这个 pl/pgSQL 函数

drop function if exists f( float );
create function f( x float )
  returns float
  language plpgsql
  as $$
    begin
      return 1 / x;
    exception
      when others then
        raise notice 'oops';
        return 0::float;
    end;
  $$;
Run Code Online (Sandbox Code Playgroud)

很明显,这select f( 0 );将导致代码 22012 异常,类型division_by_zeroexception知道了这一点,我可以将子句的选择器范围缩小到when division_by_zero then ...

但是,对于任意函数,如何获取错误类型呢?有什么类似的东西吗raise notice error.code

postgresql error-handling exception

2
推荐指数
1
解决办法
1591
查看次数