我有PostgreSQL数据库,并且有一个数据类型为'bytea'的列'image'.我无法修改列或数据库配置.JPA带注释的POJO包含跟随映射
@Column(name="image")
private byte[] image;
Run Code Online (Sandbox Code Playgroud)
返回的数据采用以下格式(这只是一个示例)
WF5ClN6RlpLZ0hJTUdNQ1FJWmkwcFVGSUdNQ0lDWUE5TUEvanRFeElwK2x0M2tBQUFBQVNVVk9SSzVDWUlJPQo=
Run Code Online (Sandbox Code Playgroud)
当我将此数据写入文件(.jpeg)时,照片查看器会说"这是损坏的文件".我也理解实际的图像字节数据与上面的示例有所不同.我读了一些博客,提到PostgreSQL将十六进制转换应用于bytea数据.如何在有或没有JPA的情况下将其恢复为原始数据?
数据库 - PostgresSQL版本9.5.1
司机
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1205-jdbc41</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 样本数据
CREATE TABLE test
(id integer, session_ID integer, value integer)
;
INSERT INTO test
(id, session_ID, value)
VALUES
(0, 2, 100),
(1, 2, 120),
(2, 2, 140),
(3, 1, 900),
(4, 1, 800),
(5, 1, 500)
;
Run Code Online (Sandbox Code Playgroud)
当前查询
select
id,
last_value(value) over (partition by session_ID order by id) as last_value_window,
last_value(value) over (partition by session_ID order by id desc) as last_value_window_desc
from test
ORDER BY id
Run Code Online (Sandbox Code Playgroud)
我在使用last_value()窗口函数时遇到问题:http :
//sqlfiddle.com/#!15/bcec0/2
在小提琴中,我尝试使用last_value()查询中的排序方向。
编辑:
问题不在于:为什么我没有得到所有时间的最后一个值,以及如何使用frame子句(unbounded preceding和 …
我正在尝试使用 node.js npm 包创建 PostgreSQL 准备好的语句pg。但是,我不断收到错误:
无法确定参数 $1 的数据类型
function promiseQuery(sql, values) {
return new Promise(function(resolve, reject) {
pool.query('select $1 from workers', ['name'], function(err, result) {
if (err) {console.log(err); reject(err)}
else resolve(result.rows);
})
});
}
Run Code Online (Sandbox Code Playgroud)
在数据库中,该name字段设置为 type text not null。
我也尝试了pg-promise,但也没有成功。
我正在使用 PostGIS/Rails 并且有一组带有地理位置的点。
class DataSet < ActiveRecord::Base # these are the sets containing the points
has_many :raw_data
# attributes: id , name
end
class RawData < ActiveRecord::Base # these are the data points
belongs_to :data_set
# attributes: id, location which is "Point(lon,lat)"
end
Run Code Online (Sandbox Code Playgroud)
对于给定的一组点,我需要找到 N 个最近的组和它们的距离;
或者: 对于给定的最大距离和一组点,我需要找到 N 个最近的组。
使用 PostGIS 执行此操作的最佳方法是什么?
我的版本是带有 PostGIS 2.1.2 的 PostgreSQL 9.3.4
我正在使用 Postgres 9.6.2 创建电影和电视节目流媒体服务数据库(用于学校项目)。我遇到以下错误:
没有与引用表“watchedepisodes”的给定键匹配的唯一约束
只要用户观看了至少一集(显示在 WatchedEpisodes 表中),下面的电视收视率表就会接受电视节目并允许用户对其进行评分。由于 WatchedEpisodes 具有用户 id、电视节目 id、季节和剧集的复合主键,因此它不允许我仅从该表中引用仅包含 uid 和 tid 的复合键。
CREATE TABLE WatchedEpisodes (
uid int unique references Users(uid),
tid int,
season int,
episode int,
FOREIGN KEY(tid, season, episode) REFERENCES Episodes(tid, season, episode),
PRIMARY KEY (uid, tid, season, episode)
);
CREATE TABLE TVRatings (
uid int,
tid int,
rating int check (rating > 0 and rating < 6),
FOREIGN KEY(uid, tid) REFERENCES WatchedEpisodes(uid,tid),
PRIMARY KEY(uid, tid)
);
Run Code Online (Sandbox Code Playgroud)
想知道是否有办法只引用该组合键的一部分。这些只是我的两个表格,因此如果需要更多信息,我可以添加更多信息。
sql database postgresql unique-constraint composite-primary-key
免责声明:显示的问题比我最初预期的要普遍得多。下面的例子取自另一个问题的解决方案。但是现在我正在使用这个示例来解决更多问题 - 主要与时间序列有关(查看右侧栏中的“链接”部分)。
所以我想先更一般地解释这个问题:
我正在使用 PostgreSQL,但我确信这个问题也存在于其他支持 DBMS 的窗口函数(MS SQL Server、Oracle 等)中。
窗口函数可用于通过公共属性或值将某些值组合在一起。例如,您可以按日期对行进行分组。然后您可以计算每个日期内的最大值或平均值或计数行或其他任何内容。
这可以通过定义一个PARTITION. 按日期分组将适用于PARTITION BY date_column. 现在,您想要在您的组中执行一个需要特殊顺序的操作(计算行号或对列求和)。这可以通过PARTITON BY date_column ORDER BY an_attribute_column.
现在考虑更精细的时间序列分辨率。如果您没有日期但有时间戳怎么办。然后你不能再按时间列分组。但是,按添加顺序分析数据可能很重要(也许时间戳是数据集的创建时间)。然后您意识到一些连续的行具有相同的值,并且您希望按此公共值对数据进行分组。但线索是行有不同的时间戳。
这里的问题是你不能做一个PARTITION BY value_column. 因为先PARTITION BY强制排序。因此,您的表将按value_column分组前排序,不再按时间戳排序。这会产生您意想不到的结果。
更一般地说:问题是即使有序列不是创建的分区的一部分,也要确保特殊排序。
例子:
我有下表:
ts val
100000 50
130100 30050
160100 60050
190200 100
220200 30100
250200 30100
300000 300
500000 100
550000 1000
600000 1000
650000 2000
700000 2000
720000 2000
750000 300
Run Code Online (Sandbox Code Playgroud)
我有一个问题,我必须对列的所有绑定值进行分组val …
我有一个TextFormField。通常,您可以使用选择工具栏通过长按/双击来复制/粘贴/全选等。
我想覆盖粘贴事件。它不应该简单地插入当前剪贴板数据,而是打开一个弹出窗口,其中包含多个要插入的选项。
是否可以以任何方式捕获并覆盖粘贴事件?我看到类似handlePaste()for 的东西SelectionControls,但我不知道如何将其添加到我的TextFormField.
提前致谢!
我有一个包含日期字段的csv数据集,我可能会也可能不会为空(='').我已将Postgres设置为在此字段上允许null,并为其指定了Date格式.当我运行我的PHP导入脚本(下面)时,导入失败,因为空字符串不是日期格式.我的理解是我应该把它设置为NULL,只有当字段实际上是空的时我才想做.所以我想有条件地设置它,我认为它会像:
<?php if (empty($data[3])){
$data[3] = NULL;
// (i've tried "null", 'null', "NULL", null, etc.)
Run Code Online (Sandbox Code Playgroud)
当我通过这种方法执行导入时,只要日期字段为空,我就会得到PHP Warning: pg_query(): Query failed: ERROR: invalid input syntax for type date: "NULL".PHP不能将NULL传递给一个pg_query?我应该将条件逻辑放在查询中吗?我的代码如下.非常感谢您的任何建议.
<?php
$conn_string = "host=localhost port=5432 dbname=mydb user=myusername password=mypassword";
$_db = pg_connect($conn_string);
$fileName = "../feeds/stale_prod_report.20111215.csv";
$row = 0;
if ($_db->connect_error) {
die('Connection Error (' . $_db->connect_errno . ') ' . $_db->connect_error);
}
if (($handle = fopen($fileName, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的MacOSX 10.9.4上运行PostgreSQL并运行.
我按照此处列出的说明使用Homebrew成功安装了PostgreSQL:https://www.codefellows.org/blog/how-to-install-postgresql.它已经启动,我可以使用该psql命令连接到它.
但是,当我尝试创建postgis扩展时,它失败了(见下文).我知道我需要安装postgresql-contrib-9.3.
$ psql -d mydb
psql (9.3.5)
Type "help" for help.
mydb=# CREATE EXTENSION postgis;
ERROR: could not open extension control file "/usr/local/Cellar/postgresql/9.3.5/share/postgresql/extension/postgis.control": No such file or directory
Run Code Online (Sandbox Code Playgroud)
如何postgresql-contrib-9.3在Mac OSX上安装它?我没有apt-get.我看到的说明根本不清楚如何安装它.有人可以建议吗?
来自命令python setup.py egg_info的完整输出:运行egg_info创建pip-egg-info / psycopg2.egg-info编写pip-egg-info / psycopg2.egg-info / PKG-INFO将顶级名称写入pip-egg- info / psycopg2.egg-info / top_level.txt写入dependency_links到pip-egg-info / psycopg2.egg-info / dependency_links.txt写入清单文件'pip-egg-info / psycopg2.egg-info / SOURCES.txt'错误:无法从'10 .4'确定PostgreSQL版本
/ tmp / pip-install-lR9u0X / psycopg2 /中的命令“ python setup.py egg_info”失败,错误代码为1
有谁知道是什么问题?尝试在virtualenv中运行pgadmin,由于该错误而无法找出原因。谢谢
postgresql ×9
sql ×3
bytea ×1
database ×1
flutter ×1
geospatial ×1
gis ×1
hibernate ×1
java ×1
javascript ×1
jpa ×1
macos ×1
node.js ×1
paste ×1
pg ×1
pg-promise ×1
php ×1
postgis ×1
psycopg2 ×1
python ×1