首页 \ 问答 \ PostgreSQL array_agg(INTEGER [])(PostgreSQL array_agg(INTEGER[]))

PostgreSQL array_agg(INTEGER [])(PostgreSQL array_agg(INTEGER[]))

使用Postgres 9.5,我想从GROUP BY中继承整数数组。 从文档看似似乎array_agg应该能够做到这一点,但我得到: ERROR: cannot accumulate arrays of different dimensionality

在我的测试集上使用array_dims,得到[1:18],[1:24]和[1:48]。 我将其视为3个不同长度的1维阵列。 结果应该是一个维度为[1:90]的单个数组我在这里缺少什么?


Using Postgres 9.5, I want to concaternate integer arrays from a GROUP BY. From the documentation is seems as though array_agg should be able to do this, but I get: ERROR: cannot accumulate arrays of different dimensionality

Using array_dims on my test set I get [1:18], [1:24] and [1:48]. I see this as 3 1-dimensional arrays of different lengths. The result should be a single array with dimension [1:90] What am I missing here?


原文:https://stackoverflow.com/questions/46849237
更新时间:2024-03-31 18:03

最满意答案

嘿克里斯托夫尝试这个(你的例子有一些修改):

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.Qsci import *

# -----------------------------------
# | A sample of C-code, pasted into |
# | the QScintilla editor           |
# -----------------------------------
myCodeSample = r"""#include <stdio.h>

/*
 * I want an image
 * right here =>
 */

int main()
{
    char arr[5] = {'h', 'e', 'l', 'l', 'o'};

    int i;

    for(i = 0; i < 5; i++) {
        printf(arr[i]);
    }

    return 0;

}""".replace("\n","\r\n")


# --------------------------------------------------
class MyScintilla(QsciScintilla):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.image = QImage("qscintilla_logo.png")

    def paintEvent(self, e):
        super().paintEvent(e)
        # Get paint rectangle size
        current_parent_size = self.size()
        image_line = 4
        image_column = 17
        # Find the paint offset
        line_height = 20
        font_width = 10
        first_visible_line = self.SendScintilla(self.SCI_GETFIRSTVISIBLELINE)
        paint_offset_x = image_column * font_width
        paint_offset_y = (image_line - first_visible_line) * line_height
        # Paint the image
        painter = QPainter()
        painter.begin(self.viewport())
        painter.drawImage(QPoint(paint_offset_x,paint_offset_y), self.image)
        painter.end()


class CustomMainWindow(QMainWindow):
    def __init__(self):
        super(CustomMainWindow, self).__init__()

        # ---------------------------
        # |      Window setup       |
        # ---------------------------

        # 1. Define the geometry of the main window
        # ------------------------------------------
        self.setGeometry(300, 300, 800, 400)
        self.setWindowTitle("QScintilla Test")

        # 2. Create frame and layout
        # ---------------------------
        self.__frm = QFrame(self)
        self.__frm.setStyleSheet("QWidget { background-color: #ffeaeaea }")
        self.__lyt = QVBoxLayout()
        self.__frm.setLayout(self.__lyt)
        self.setCentralWidget(self.__frm)
        self.__myFont = QFont("Consolas", 14, weight=QFont.Bold)
        self.__myFont.setPointSize(14)

        # 3. Place a button
        # ------------------
        self.__btn = QPushButton("Qsci")
        self.__btn.setFixedWidth(50)
        self.__btn.setFixedHeight(50)
        self.__btn.clicked.connect(self.__btn_action)
        self.__btn.setFont(self.__myFont)
        self.__lyt.addWidget(self.__btn)

        # ---------------------------
        # | QScintilla editor setup |
        # ---------------------------

        # 1. Make instance of QSciScintilla class
        # ----------------------------------------
        self.__editor = MyScintilla()
        self.__editor.setText(myCodeSample)
        self.__editor.setLexer(None)
        self.__editor.setUtf8(True)  # Set encoding to UTF-8
        self.__editor.setFont(self.__myFont)  # Can be overridden by lexer


        # 3. Add editor to layout
        # ------------------------
        self.__lyt.addWidget(self.__editor)

        self.show()

    ''''''

    def __btn_action(self):
        print("Hello World!")

    ''''''


''' End Class '''

if __name__ == '__main__':
    app = QApplication(sys.argv)
    QApplication.setStyle(QStyleFactory.create('Fusion'))
    myGUI = CustomMainWindow()

    sys.exit(app.exec_())

''''''

它只是继承QsciScintilla类并重载它的paintEvent方法。 诀窍是获取图像相对于文档视图的坐标。 对于这个例子,我justed猜测了行高和字体宽度,它可能是从QScintilla获得的。 另一件事是我只是用行和列偏移硬编码图像的位置,创建一个编辑器可以解析并自动插入图像的语法可能会很好。

问候


Hey Kristof try this (your example with some modifications):

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.Qsci import *

# -----------------------------------
# | A sample of C-code, pasted into |
# | the QScintilla editor           |
# -----------------------------------
myCodeSample = r"""#include <stdio.h>

/*
 * I want an image
 * right here =>
 */

int main()
{
    char arr[5] = {'h', 'e', 'l', 'l', 'o'};

    int i;

    for(i = 0; i < 5; i++) {
        printf(arr[i]);
    }

    return 0;

}""".replace("\n","\r\n")


# --------------------------------------------------
class MyScintilla(QsciScintilla):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.image = QImage("qscintilla_logo.png")

    def paintEvent(self, e):
        super().paintEvent(e)
        # Get paint rectangle size
        current_parent_size = self.size()
        image_line = 4
        image_column = 17
        # Find the paint offset
        line_height = 20
        font_width = 10
        first_visible_line = self.SendScintilla(self.SCI_GETFIRSTVISIBLELINE)
        paint_offset_x = image_column * font_width
        paint_offset_y = (image_line - first_visible_line) * line_height
        # Paint the image
        painter = QPainter()
        painter.begin(self.viewport())
        painter.drawImage(QPoint(paint_offset_x,paint_offset_y), self.image)
        painter.end()


class CustomMainWindow(QMainWindow):
    def __init__(self):
        super(CustomMainWindow, self).__init__()

        # ---------------------------
        # |      Window setup       |
        # ---------------------------

        # 1. Define the geometry of the main window
        # ------------------------------------------
        self.setGeometry(300, 300, 800, 400)
        self.setWindowTitle("QScintilla Test")

        # 2. Create frame and layout
        # ---------------------------
        self.__frm = QFrame(self)
        self.__frm.setStyleSheet("QWidget { background-color: #ffeaeaea }")
        self.__lyt = QVBoxLayout()
        self.__frm.setLayout(self.__lyt)
        self.setCentralWidget(self.__frm)
        self.__myFont = QFont("Consolas", 14, weight=QFont.Bold)
        self.__myFont.setPointSize(14)

        # 3. Place a button
        # ------------------
        self.__btn = QPushButton("Qsci")
        self.__btn.setFixedWidth(50)
        self.__btn.setFixedHeight(50)
        self.__btn.clicked.connect(self.__btn_action)
        self.__btn.setFont(self.__myFont)
        self.__lyt.addWidget(self.__btn)

        # ---------------------------
        # | QScintilla editor setup |
        # ---------------------------

        # 1. Make instance of QSciScintilla class
        # ----------------------------------------
        self.__editor = MyScintilla()
        self.__editor.setText(myCodeSample)
        self.__editor.setLexer(None)
        self.__editor.setUtf8(True)  # Set encoding to UTF-8
        self.__editor.setFont(self.__myFont)  # Can be overridden by lexer


        # 3. Add editor to layout
        # ------------------------
        self.__lyt.addWidget(self.__editor)

        self.show()

    ''''''

    def __btn_action(self):
        print("Hello World!")

    ''''''


''' End Class '''

if __name__ == '__main__':
    app = QApplication(sys.argv)
    QApplication.setStyle(QStyleFactory.create('Fusion'))
    myGUI = CustomMainWindow()

    sys.exit(app.exec_())

''''''

It is just subclassing the QsciScintilla class and overloading it's paintEvent method. The trick is to get the coordinates of where the image is in relation to the view of the document. For the example I justed guessed the line height and font width, it can probably be obtained from the QScintilla. The other thing is I just hard coded the position of the image with a line and column offset, it would probably be good to create a syntax that the editor could parse and insert the image automatically.

Regards

相关问答

更多
  • 您可以使用JavaFX画布执行此操作,如Canvas教程 “与用户交互”一节所示。 你不需要java.awt.Canvas 。 您可以拍摄画布(或任何其他节点)的快照以创建图像。 您可以使用PixelReader从现有图像读取像素图并使用从Imageable教程中显示的WritableImage获得的PixelWriter写入图像的像素图。 要将结果图像写入磁盘, 请将其转换为BufferedImage并使用ImageIO写出。 如果你需要它,缩放图像的样本会变成像素化形式(类似于Microsoft Pai ...
  • 一种使用Pyqt5的方法,其中包含可点击的函数和变量。 您的可点击部分Quoted out的脚本在PyQt5中看起来像这样,带有自定义信号。 PyQt4信号 self.connect(self,SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'), self.on_margin_clicked) PyQt5信号 self.marginClicked.connect(self.on_margin_clicked) PyQt5 import sy ...
  • 默认编辑器可以上传图像。 它是否作为管理员工作? 如果是这样,您需要启动用户滚动以获得更多权限。 它应该是作者或更高。 更多信息请查找upload_files http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table The default editor can upload images. Does it work as an admin? If so you need to up your user-roll ...
  • CKEditor支持它。 查看开发者指南 。 TinyMCE确实不支持开箱即用。 但是有插件可供选择。 CKEditor supports it. Check the developer guide. TinyMCE indeed doesn't support it out of the box. But there are plugins for this.
  • 做一个快速的谷歌搜索带来了以下内容: http://gitorious.org/pyside-qscintilla https://github.com/LuaDist/scintilla/tree/master/qt/ScintillaEditPy 我怀疑第一个是直接端口,而第二个是一些闪烁包装而不是QScintilla端口。 Doing a quick Google search brought up the following: http://gitorious.org/pyside-qscintil ...
  • 我分了一个夏令营Jsfiddle的例子。 它在这里工作 您可以尝试使用onMediaDelete事件和$target.context.dataset.filename来获取要删除的图像的文件名。 $(".summernote").summernote({ onMediaDelete : function($target, editor, $editable) { alert($target.context.dataset.filename); $ta ...
  • 嘿克里斯托夫尝试这个(你的例子有一些修改): import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.Qsci import * # ----------------------------------- # | A sample of C-code, pasted into | # | the QScintilla editor | ...
  • 您要做的是使用TextLineMetrics 。 您可以使用getLineMetrics()函数获取此信息。 看看这些链接,如果你还有一些问题,请告诉我,我会尽力帮你解决。 但基本上你可以获得文本字段的行度量,然后将该信息发送到php而不仅仅是容器位置。 您需要为文本字段中的每一行执行此操作。 TextLineMetrics将帮助您定位和调整文本大小,以确保您可以正确排列。 What you want to do is use the TextLineMetrics. You can get this in ...
  • 我得到了答案参考这个 http://web.archive.org/web/20150302041833/http://www.codeproject.com/Articles/22776/WPF-DrawTools 本文介绍的程序允许用户使用鼠标和某些绘图工具在WPF窗口上绘制图形对象。 该程序支持以下工具:矩形,椭圆,线,铅笔和文本。 我的第一篇DrawTools文章展示了如何使用Windows窗体执行此操作。 在WPF版本中,我实现了之前文章读者所要求的一些其他功能: 文本工具XML序列化背景图像上的 ...

相关文章

更多

最新问答

更多
  • linux环境下怎么用maven编译一个已有的java项目?
  • Ionic2和IonicDeploy(Ionic2 and IonicDeploy)
  • 尝试分组和别名数据时出错(Error when Attempting to Group and Alias Data)
  • Facebook PHP API错误代码100:API中提供的appsecret_proof无效(Facebook PHP API Error code 100: Invalid appsecret_proof provided in the API)
  • 不用u盘和光盘怎么安装linux系统
  • 表名作为变量参数(Table name as variable parameter)
  • 我想学计算机 在望京花园住 附近那有这样的地方可以学
  • 删除原始记录的重复项(Removing duplicates with original records)
  • Pandas:使用.astype(str)时忽略空值?(Pandas: ignore null values when using .astype(str)?)
  • Python新手阵列 - 列表转换[重复](Python newbie array - list conversion [duplicate])
  • java.lang.String cannot be cast to java.lang.Float
  • 带参数的选择器(Selector with argument)
  • python中的for循环语法(for loop syntax in python)
  • Nunit - 无法检索类别属性(NUnit - Can't retrieve a category property)
  • python3 xpath无法到达子节点(AttributeError:'NoneType'对象没有属性'text')(python3 xpath can't reach a child node (AttributeError: 'NoneType' object has no attribute 'text'))
  • Android自动 - 如何启用开发人员模式(Android auto - how to enable developer mode)
  • java weka stringtowordvector没有正确计算单词出现次数(java weka stringtowordvector is not counting word occurences properly)
  • 如何解释DHT响应中的“节点”?(How to interpret 'nodes' in a DHT response?)
  • 什么是使用opencv和树莓相机模块进行人脸检测的最佳算法(What is the best algorithm for face detection using opencv and raspberry camera module)
  • 可以somone解释这两个问题的解决方案(c程序,mutex,线程)吗?(Can someone explain the solution of these two questions (c program,mutex,threads)?)
  • 如何解决SyntaxError:意想不到的令牌var gulp(How to fix SyntaxError: Unexpected token var in gulp)
  • 在满足R中的第一个实例后,在所有行中分配值(Assign value in all rows following satisfaction of first instance in R)
  • 如何记录Atk4 auth /登录事件(How to log Atk4 auth/login event)
  • 是否有必要在新的scala项目中添加我的自定义scala库依赖项?(is it necessary to add my custom scala library dependencies in new scala project?)
  • Java中对象类的继承(Inheritance of Object Class in Java)
  • 如何在jquery自动完成中获取当前元素?(How to get current element in jquery autocomplete?)
  • 学电子商务甚么大学好
  • @Override在java中(@Override in java)
  • 虚拟机中怎么给linux装office
  • Laravel邮件参数(sendmail / smtp)(Laravel mail parameters (sendmail/smtp))