尝试使用PostgreSQL将数据加载到表中?

时间:2018-07-29 16:08:00

标签: sql postgresql pgadmin-4

我正在尝试使用PostgresSQL10.4和pgAdmin4将数据加载到表中。我的查询如下。当我尝试使用\ copy时,出现以下错误。

import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.2

ApplicationWindow {
    visible: true
    width: 640
    height: 240
    title: qsTr("PyQt5 love QML")
    color: "whitesmoke"

    GridLayout {
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.margins: 9

        columns: 4
        rows: 4
        rowSpacing: 10
        columnSpacing: 10

        Text {
            text: qsTr("First number")
        }

        // Input field of the first number
        TextField {
            id: firstNumber
        }

        Text {
            text: qsTr("Second number")
        }

        // Input field of the second number
        TextField {
            id: secondNumber
        }

        Button {
            height: 40
            Layout.fillWidth: true
            text: qsTr("Sum numbers")

            Layout.columnSpan: 2

            onClicked: {
                // Invoke the calculator slot to sum the numbers
                sumResult.text = calculator.sum(firstNumber.text, secondNumber.text)
            }
        }

        Text {
            text: qsTr("Result")
        }

        // Here we see the result of sum
        Text {
            id: sumResult
        }

        Button {
            height: 40
            Layout.fillWidth: true
            text: qsTr("Subtraction numbers")

            Layout.columnSpan: 2

            onClicked: {
                // Invoke the calculator slot to subtract the numbers
                subResult.text = calculator.sub(firstNumber.text, secondNumber.text)
            }
        }

        Text {
            text: qsTr("Result")
        }

        // Here we see the result of subtraction
        Text {
            id: subResult
        }
    }
}

以上结果导致以下错误:

错误:

CREATE TABLE mydata (TimeDate date, Yield float(3))
SELECT * FROM mydata
\copy mydata FROM 'C:\Users\john\Desktop\Stock Prices.csv' WITH CSV;

2 个答案:

答案 0 :(得分:1)

\copy是psql程序特有的工具。其他程序也有自己的变体来完成相同的任务。如果是PgAdmin4,则在树查看器中的表上单击鼠标右键,然后选择“导入/导出...”

答案 1 :(得分:1)

您可以右键单击该特定表并选择“导入/导出数据”选项,然后提供要加载到该表中的文件。