【问题标题】:Postgresql: syntax error at or near ""ViewShifts"" why do i get this error with the query below?Postgresql: 在 ""ViewShifts"" 处或附近出现语法错误 为什么我在下面的查询中会出现此错误?
【发布时间】:2021-05-14 21:22:56
【问题描述】:
    await queryInterface.sequelize.query(`
    CREATE OR REPLACE "ViewShifts" AS
    select
      s.id,
      s.facility_id,
      s.assigned_nurse_id,
      case when u.id is not null
        then jsonb_build_object(
          'id', u.id,
          'name', u.name,
          'rating', u.rating,
          'image', u.image->>'src'
        )
        else null
      end as "assignedNurse",
      case when p.id is not null
        then jsonb_build_object(
          'id', p.id,
          'paymentDate', p."paymentDate",
          'isPaymentDateDefault', p."isPaymentDateDefault",
          'status', p.status,
          'type', p.type,
          'netPay', p."netPay",
          'comment', p.comment,
          'reason', p.reason
        )
        else null
      end as payment,
      p.adjustments as "paymentAdjustments",
      s.role,
      s.type,
      s.unit,
      s."unitDescription",
      s.start_time,
      s.end_time,
      s.rate,
      s.net_pay,
      s.qualifications,
      s.description,
      s.status,
      s."prevStatus",
      s."statusUpdatedAt",
      s."breakTime",
      s.review,
      s."isMinPaymentEnabled",
      s."applicantLocationStatus",
      "checkIn".id as "checkInId",
      "checkIn"."selectedTime" as "checkInTime",
      "checkIn"."createdAt" as "checkInCreatedAt",
      "checkOut".id as "checkOutId",
      "checkOut"."selectedTime" as "checkOutTime",
      "checkOut"."createdAt" as "checkOutCreatedAt",
      "checkOut"."rating" as "ratingFromNurse",
      s."applicantCount" as applicants,
      f.id as "facilityId",
      f.name as "facilityName",
      f.short_name as "facilityShortName",
      f.timezone as "facilityTimezone",
      f."segmentId",
      f."segmentName",
      s."createdAt",
      s."updatedAt",
      s."deletedAt",
      s."cancelledAt"
      s."autoSelectApplicant",
      s."autoSelectApplicantSelected",
      s."autoSelectType",
      from shifts s
      left join facilities f on (s.facility_id = f.id and f."deletedAt" is null)
      left join users u on (s.assigned_nurse_id = u.id)
      left join "CheckEvents" as "checkIn" on (s."actualCheckInId" = "checkIn".id)
      left join "CheckEvents" as "checkOut" on (s."actualCheckOutId" = "checkOut".id)
      left join "Payments" as p on (p."shiftId" = s.id and p.type <> 'other');
    `);

请问“ViewShifts”错误处或附近出现语法错误的原因是什么?任何帮助将不胜感激。

我正在尝试修改现有的 Postgres 视图。我还能怎么办?

请问“ViewShifts”错误处或附近出现语法错误的原因是什么?任何帮助将不胜感激。

我正在尝试修改现有的 Postgres 视图。我还能怎么办?

【问题讨论】:

    标签: node.js postgresql sequelize.js postgresql-9.4


    【解决方案1】:

    您的代码中有一些语法错误

    CREATE OR REPLACE VIEW "ViewShifts" AS
    select
      s.id,
      s.facility_id,
      s.assigned_nurse_id,
      case when u.id is not null
        then jsonb_build_object(
          'id', u.id,
          'name', u.name,
          'rating', u.rating,
          'image', u.image->>'src'
        )
        else null
      end as "assignedNurse",
      case when p.id is not null
        then jsonb_build_object(
          'id', p.id,
          'paymentDate', p."paymentDate",
          'isPaymentDateDefault', p."isPaymentDateDefault",
          'status', p.status,
          'type', p.type,
          'netPay', p."netPay",
          'comment', p.comment,
          'reason', p.reason
        )
        else null
      end as payment,
      p.adjustments as "paymentAdjustments",
      s.role,
      s.type,
      s.unit,
      s."unitDescription",
      s.start_time,
      s.end_time,
      s.rate,
      s.net_pay,
      s.qualifications,
      s.description,
      s.status,
      s."prevStatus",
      s."statusUpdatedAt",
      s."breakTime",
      s.review,
      s."isMinPaymentEnabled",
      s."applicantLocationStatus",
      "checkIn".id as "checkInId",
      "checkIn"."selectedTime" as "checkInTime",
      "checkIn"."createdAt" as "checkInCreatedAt",
      "checkOut".id as "checkOutId",
      "checkOut"."selectedTime" as "checkOutTime",
      "checkOut"."createdAt" as "checkOutCreatedAt",
      "checkOut"."rating" as "ratingFromNurse",
      s."applicantCount" as applicants,
      f.id as "facilityId",
      f.name as "facilityName",
      f.short_name as "facilityShortName",
      f.timezone as "facilityTimezone",
      f."segmentId",
      f."segmentName",
      s."createdAt",
      s."updatedAt",
      s."deletedAt",
      s."cancelledAt",
      s."autoSelectApplicant",
      s."autoSelectApplicantSelected",
      s."autoSelectType"
      from shifts s
      left join facilities f on (s.facility_id = f.id and f."deletedAt" is null)
      left join users u on (s.assigned_nurse_id = u.id)
      left join "CheckEvents" as "checkIn" on (s."actualCheckInId" = "checkIn".id)
      left join "CheckEvents" as "checkOut" on (s."actualCheckOutId" = "checkOut".id)
      left join "Payments" as p on (p."shiftId" = s.id and p.type <> 'other');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      • 1970-01-01
      • 2021-12-04
      • 2020-02-05
      • 2021-12-13
      • 2021-12-24
      • 1970-01-01
      相关资源
      最近更新 更多