什么是"E"?在Postgres字符串之前? [英] What's the "E" before a Postgres string?

查看:684
本文介绍了什么是"E"?在Postgres字符串之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读这样的Postgres/PostGIS声明:

I was reading a Postgres/PostGIS statement like this:

SELECT ST_AsBinary(
ST_GeomFromWKB(
  E'\\001\\001\\000\\000\\000\\321\\256B\\312O\\304Q\\300\\347\\030\\220\\275\\336%E@',
  4326
  )
);

上面的代码从一个众所周知的二进制文件(WKB)中创建了一些东西.我还没有看到这里引用的具体方式,其中字符串用单引号引起来,并在引号前加上E.

The above creates something from a Well Known Binary (WKB). I haven't seen the specific way of quoting here where the string is single quoted with a E preceding the beginning quote.

这种格式叫什么?格式化的规则是什么?例如336%E@到底是特殊字符还是只是二进制值?

What is this format called? And what are the formatting rules for this? e.g. is the 336%E@ at the very end special or just some binary value?

这是与Postgres9.3/9.4一起使用的; PostGIS 2.1.

This is with Postgres9.3/9.4; PostGIS 2.1.

推荐答案

根据PostgreSQL文档

As per the PostgreSQL documentation http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html (emphasis mine)

PostgreSQL还接受转义"字符串常量,这是SQL标准的扩展. 通过在开头的单引号之前写字母E(大写或小写)来指定转义字符串常量,例如E'foo'. (当跨行继续使用转义字符串常量时,请仅在第一个引号前写E.)在转义字符串中,反斜杠字符(\)开始一个类似C的反斜杠转义序列,其中反斜杠的组合后面的字符表示特殊的字节值

PostgreSQL also accepts "escape" string constants, which are an extension to the SQL standard. An escape string constant is specified by writing the letter E (upper or lower case) just before the opening single quote, e.g., E'foo'. (When continuing an escape string constant across lines, write E only before the first opening quote.) Within an escape string, a backslash character (\) begins a C-like backslash escape sequence, in which the combination of backslash and following character(s) represent a special byte value

在字符串中使用\\表示它正在转义转义序列,可能是为了安全地传输和存储在.sql文件中.实际上传递给ST_GeomFromWKB函数的 verbatim 字符串为:

The use of \\ in your string means that it's escaping an escape sequence, probably to be safe in transit and storage in a .sql file. The verbatim string actually passed into the ST_GeomFromWKB function will be:

\001\001\000\000\000\321\256B\312O\304Q\300\347\030\220\275\336%E@

这些由斜线之间的3或4个字符组成的序列将直接由ST_GeoFromWKB解释.

These sequences of 3 or 4 characters between slashes would then be interpreted by ST_GeoFromWKB directly.

ST_GeoFromWKB的文档( http://postgis.org/docs/ST_GeomFromWKB.html)状态:

ST_GeomFromWKB函数采用几何的众所周知的二进制表示形式和空间参考系统ID(SRID),并创建适当的几何类型的实例.此函数在SQL中扮演几何工厂"的角色.这是ST_WKBToSQL的备用名称.

The ST_GeomFromWKB function, takes a well-known binary representation of a geometry and a Spatial Reference System ID (SRID) and creates an instance of the appropriate geometry type. This function plays the role of the Geometry Factory in SQL. This is an alternate name for ST_WKBToSQL.

不幸的是,它没有说明确切的格式是众所周知的二进制表示形式".

Unfortunately it doesn't state what format, exactly, the "well-known binary representation" actually is.

事实证明,字符串的内容取决于您使用的坐标系,该坐标系由SRID参数指定.在这种情况下,4326对应于WGS84: https://en.wikipedia.org/wiki /World_Geodetic_System#WGS84

It turns out that the content of the string depends on the coordinate system you're using, which is specified by the SRID parameter. In this case 4326 corresponds to WGS84: https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84

您需要做进一步的阅读和研究才能弄清楚.

You'll need to do further reading and research to untangle that.

这篇关于什么是"E"?在Postgres字符串之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆