小编joa*_*olo的帖子

如何将.sql文件的内容读入R脚本以运行查询?

我已经尝试了readLinesread.csv功能,但后来没有工作.

这是my_script.sql文件的内容:

SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees
WHERE HireDate >= '1-july-1993'
Run Code Online (Sandbox Code Playgroud)

它保存在我的桌面上.

现在我想从我的R脚本运行此查询.这是我有的:

conn = connectDb()

fileName <- "C:\\Users\\me\\Desktop\\my_script.sql"
query <- readChar(fileName, file.info(fileName)$size)

query <- gsub("\r", " ", query)
query <- gsub("\n", " ", query)
query <- gsub("", " ", query)

recordSet <- dbSendQuery(conn, query)
rate <- fetch(recordSet, n = -1)

print(rate)
disconnectDb(conn)
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我没有得到任何回报.我该怎么办?

sql postgresql r

16
推荐指数
4
解决办法
2万
查看次数

XAMPP - 错误:MySQL意外关闭

我出于某种原因重新安装了XAMPP并且MySQL无法运行,在控制台中出现以下错误:

01:56:03  [mysql]   Error: MySQL shutdown unexpectedly.
01:56:03  [mysql]   This may be due to a blocked port, missing dependencies, 
01:56:03  [mysql]   improper privileges, a crash, or a shutdown by another method.
01:56:03  [mysql]   Check the "/xampp/mysql/data/mysql_error.log" file
01:56:03  [mysql]   and the Windows Event Viewer for more clues
Run Code Online (Sandbox Code Playgroud)

检查"/xampp/mysql/data/mysql_error.log"文件时,我得到:

130302  1:48:06  InnoDB: Waiting for the background threads to start
130302  1:48:07 InnoDB: 1.1.8 started; log sequence number 1600324627
130302  1:48:07 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
130302  1:48:07 [Note]   - …
Run Code Online (Sandbox Code Playgroud)

mysql xampp

8
推荐指数
5
解决办法
13万
查看次数

从另一个表填充随机数据

update dataset1.test
   set column4 = (select column1 
                 from dataset2
                 order by random()
                 limit 1
                 ) 
Run Code Online (Sandbox Code Playgroud)

我必须更新第4列的dataset1,每一行都更新数据集2列中的一个随机条目。但是到目前为止,在上述查询中,我在dataset1的所有行中都只有一个随机条目,而我希望它都相同是随机的。

postgresql amazon-redshift

5
推荐指数
1
解决办法
1061
查看次数

联合查询在一列上不同

我希望第二个查询的结果覆盖第一个查询的结果:

SELECT "panel_restaurants_restaurant"."id",
       "panel_restaurants_restaurant"."name",
       "panel_restaurants_restaurant"."logo",
       "panel_restaurants_restaurantfeatures"."currency" AS "currency",
       ST_DistanceSphere(location, ST_GeomFromText('POINT(0.0 0.0)',4326)) AS "distance",
       "panel_meals_meal"."id" AS "meal_id",
       "panel_meals_meal"."status" AS "meal_status",
       "panel_meals_meal"."available_count" AS "available_dishes",
       "panel_meals_meal"."discount_price" AS "discount_price",
       "panel_meals_meal"."normal_price" AS "normal_price",
       "panel_meals_meal"."collection_from" AS "pickup_from",
       "panel_meals_meal"."collection_to" AS "pickup_to",
       "panel_meals_meal"."description" AS "meal_description"
FROM "panel_restaurants_restaurant"
INNER JOIN "panel_restaurants_restaurantfeatures" ON (
    "panel_restaurants_restaurantfeatures"."restaurant_id" = "panel_restaurants_restaurant"."id")
LEFT OUTER JOIN "panel_meals_meal" ON ("panel_restaurants_restaurant"."id" = "panel_meals_meal"."restaurant_id"
                AND "panel_meals_meal"."status" = 0
                AND (
                ("panel_meals_meal"."collection_from" AT TIME ZONE 'Europe/Warsaw')::date = DATE 'today' OR
                ("panel_meals_meal"."collection_from" AT TIME ZONE 'Europe/Warsaw')::date = DATE 'tomorrow'
                )
                AND …
Run Code Online (Sandbox Code Playgroud)

sql postgresql union join coalesce

4
推荐指数
1
解决办法
4241
查看次数

如何使用Retrofit/Android将位图发布到服务器

我正在尝试使用Android和将位图发布到服务器Retrofit.

目前我知道如何发布文件,但我更喜欢直接发送位图.

这是因为用户可以从他们的设备中挑选任何图像.我想在发送到服务器之前调整它以节省带宽,并且最好不必加载它,调整大小,将其作为文件保存到本地存储然后发布文件.

有人知道如何发布位图Retrofit吗?

android retrofit

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

在引导模块窗口中无法读取未定义输入文件的属性“ 0”

我正在尝试在Bootstrap模态中创建一个表单。它应该包含输入文件字段并预览选定的图像,因此我可以使用Jcrop裁剪图像。

所以这是我现在在做什么:

<script type="text/javascript">
    $('#new-menu').on('shown.bs.modal', function (event) {
        var modal = $(this);

        var src = modal.find(".modal-body .upload");
        var target = modal.find(".image");

        src.bind("change", function () {
            // fill fr with image data
            modal.find(".jcrop-holder").remove();
            readUrl(modal,target,src);
            initJcrop(target);
        });
    });

    function readUrl(modal,target,src){
        if (src.files && src.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                target.attr('src', e.target.result);
            };
            reader.readAsDataURL(input.files[0]);
            initJcrop(target, modal);
        }
        else alert(src.files[0]);
    }
    }


    function showCoords(c) {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#w').val(c.w);
        $('#h').val(c.h);
    }

    function initJcrop(img) {
        jcrop_api = $.Jcrop(img);

        jQuery(img).Jcrop({
            aspectRatio: …
Run Code Online (Sandbox Code Playgroud)

javascript jcrop twitter-bootstrap

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

从 PostgreSQL 中的年份和月份值生成日期

您好,我在将串联日期值转换为实际日期时遇到两个问题。

我已经厌倦了在这里寻找转换串联值,to_char(DATE ...)但我不断收到奇怪的日期。我认为这是因为我的月份前面没有零填充。

这是我的基本查询:

SELECT 

   expiry_month,
   expiry_year,
   to_date(CONCAT(expiry_year, expiry_month), 'YYYY/MM'),

FROM thisTable
Run Code Online (Sandbox Code Playgroud)

以下是数据输出的示例:

expiry_month    expiry_year   concatvalues
9               2018          20189-01-01   
1               2019          20191-01-01
5               2016          20165-01-01
3               2019          20193-01-01
10              2017          201710-01-01
2               2020          20202-01-01
Run Code Online (Sandbox Code Playgroud)

我想我需要LPAD()我的月份值才能解析正确的日期。例如,01 不是 1,05 不是 5。

但是,当我尝试 LPAD 月份值时,它不起作用。我试过了:

lpad(to_char(expiry_month),2,'0'),

我收到此错误“提示:没有函数与给定名称和参数类型匹配。您可能需要添加显式类型转换。

我不明白,因为 lpad 是一个函数。关于如何使用有什么建议吗LPAD()

谢谢你的建议。

编辑1

我尝试to_date()用以下代码更新该函数:

to_date(CONCAT(payment_cards.expiry_year || ' - ' || payment_cards.expiry_month || ' - 01'), 'YYYY-MM-01')现在它抛出了一个不同的错误:

ERROR: invalid value "- " for "MM" …

postgresql date concatenation

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

PostgreSQL 选择 INTO 函数

我正在编写一个函数,它将选择结果输出并将其汇总到一个新表中 - 因此我尝试使用 INTO 函数。但是,我的独立代码可以工作,但是一旦进入函数,我就会收到一条错误消息,指出新的 SELECT INTO 表不是已定义的变量(也许我遗漏了一些东西)。请看下面的代码:

CREATE OR REPLACE FUNCTION rev_1.calculate_costing_layer()
  RETURNS trigger AS
$BODY$
BEGIN
   -- This will create an intersection between pipelines and sum the cost to a new table for output
   -- May need to create individual cost columns- Will also keep infrastructure costing seperated
   --DROP table rev_1.costing_layer;
   SELECT inyaninga_phases.geom, catchment_e_gravity_lines.name, SUM(catchment_e_gravity_lines.cost) AS gravity_sum
   INTO rev_1.costing_layer
   FROM rev_1.inyaninga_phases 
   ON ST_Intersects(catchment_e_gravity_lines.geom,inyaninga_phases.geom)
   GROUP BY catchment_e_gravity_lines.name, inyaninga_phases.geom;
  RETURN NEW;
END;
$BODY$
language plpgsql
Run Code Online (Sandbox Code Playgroud)

postgresql postgis create-table insert-into

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